2

我正在尝试在 JSP 页面上嵌入 Angular 应用程序,出于某些原因,我需要浏览器来保留状态并且不希望 Angular 将新状态推送到浏览器历史记录。

根据Angular 文档 { skipLocationChange: true },我可以这样做。下面是我修改后的代码。

this.router.navigate(['/customComponent'],{ skipLocationChange: true });

Angular 仍然在浏览器历史中推动新的历史状态。

state: {navigationId: 2}

下面是控制台快照。

在此处输入图像描述

路由代码有什么问题吗?或者我缺少任何参数。

4

2 回答 2

2

问题是 app.module.ts 中的路由配置。由于 Angular 将默认路径路由到customComponent,它会修改状态并且没有提供传递skipLocationChange参数的规定,我不得不使用skipLocationChange从 appComponent 构造函数重新路由到 customComponent ,这在我的例子中是自举的。

根据编写的代码,直接引导 customComponent 也将有所帮助。

const appRoutes: Routes = [
{
    path: '',
    redirectTo: "/customComponent",
    pathMatch: 'full'
},
于 2019-04-19T07:31:11.487 回答
0

我用这个 this.router.navigate(['process-form/' + processDefCustomId + '/' + taskId], { skipLocationChange: true }); 在 constructor() 和 skipLocationChange: true 不起作用。

我将代码移至 ngOnInit() 方法并 skipLocationChange: true 有效。

于 2021-05-17T14:22:54.913 回答