angular - {skipLocationChange : true} in router. 导航不起作用;改变状态

标签 angular angular-routing window-object

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

根据 Angular documentation {skipLocationChange: true } 将允许我这样做。下面是我修改后的代码。

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

Angular 仍在浏览器历史记录中推送新的历史状态。

state: {navigationId: 2}

下面是控制台快照。

enter image description here

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

最佳答案

问题出在 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/

相关文章:

javascript - 迭代窗口对象的属性时出现异常 "Component is not available"

angular - 如何将焦点设置到 dx-text-box?

angular - dart angular2-子组件中的功能

javascript - 如何在 Angular2 中选择文本

angular - 特定组件 Angular 的动态标题

angular - 如何重定向到url中不带参数的url

javascript - JavaScript 中的 window.location.href 和 window.open() 方法

angular - 重复声明 TypeScript Getter Setter

检测到 Angular 4 循环依赖

javascript - 点符号、窗口对象及其属性