Angular 通过 'backward' 'forward' 浏览器按钮的路由器和导航
Angular Router and navigation via 'backward' 'forward' browser buttons
我有一个标准的 Angular 应用程序,它使用 Angular 路由器来控制页面导航。
如果我通过这样的代码控制导航
this.router.navigate(['component2']);
显示了正确的页面,但在浏览器中 'address bar' 我们发现类似 https://myserver.com/component2
因为我不想看到 component2 作为 url 的最后一部分,我使用下面的代码导航
this.router.navigate(['component2'], {skipLocationChange: true})
如果我这样做,通过浏览器的标准 'backward' 'forward' 按钮的导航将不再起作用。
有没有办法避免将组件的路径引用作为 url 的一部分,同时能够通过标准浏览器按钮进行导航?
我假设不会。如文档中所述:https://angular.io/docs/ts/latest/guide/router.html Angular 路由器使用地址栏作为其标准操作的一部分。
我能理解为什么您不想在地址栏中显示组件名称。为什么不将路由路径名称更改为功能?像:myserver.com/customers 或 myserver.com/products.
尝试与路由器的标准工作方式作斗争可能会使您的团队走上一条艰难的道路。
我有一个标准的 Angular 应用程序,它使用 Angular 路由器来控制页面导航。
如果我通过这样的代码控制导航
this.router.navigate(['component2']);
显示了正确的页面,但在浏览器中 'address bar' 我们发现类似 https://myserver.com/component2
因为我不想看到 component2 作为 url 的最后一部分,我使用下面的代码导航
this.router.navigate(['component2'], {skipLocationChange: true})
如果我这样做,通过浏览器的标准 'backward' 'forward' 按钮的导航将不再起作用。
有没有办法避免将组件的路径引用作为 url 的一部分,同时能够通过标准浏览器按钮进行导航?
我假设不会。如文档中所述:https://angular.io/docs/ts/latest/guide/router.html Angular 路由器使用地址栏作为其标准操作的一部分。
我能理解为什么您不想在地址栏中显示组件名称。为什么不将路由路径名称更改为功能?像:myserver.com/customers 或 myserver.com/products.
尝试与路由器的标准工作方式作斗争可能会使您的团队走上一条艰难的道路。