我正在尝试在 JSP 页面上嵌入 Angular 应用程序,由于某些原因,我需要浏览器来保留状态并且不希望 Angular 将新状态推送到浏览器历史记录。
根据 Angular documentation {skipLocationChange: true }
将允许我这样做。下面是我修改后的代码。
this.router.navigate(['/customComponent'],{ skipLocationChange: true });
Angular 仍在浏览器历史记录中推送新的历史状态。
state: {navigationId: 2}
下面是控制台快照。
路由代码有问题吗?或者我缺少任何参数。
最佳答案
问题出在 app.module.ts 中的路由配置。
由于 Angular 将默认路径路由到 customComponent
,它会修改状态,并且没有提供传递 skipLocationChange
参数的规定,因此我必须使用 skipLocationChange
重新路由到 customComponent > 来自 appComponent 构造函数,在我的例子中是引导的。
直接引导自定义组件也将有所帮助,具体取决于编写的代码。
const appRoutes: Routes = [
{
path: '',
redirectTo: "/customComponent",
pathMatch: 'full'
},
关于angular - {skipLocationChange : true} in router. 导航不起作用;改变状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55747633/