angular - router.navigate 中的 {skipLocationChange : true} 不起作用;改变状态
问题描述
我正在尝试在 JSP 页面上嵌入 Angular 应用程序,出于某些原因,我需要浏览器来保留状态并且不希望 Angular 将新状态推送到浏览器历史记录。
根据Angular 文档 { skipLocationChange: true }
,我可以这样做。下面是我修改后的代码。
this.router.navigate(['/customComponent'],{ skipLocationChange: true });
Angular 仍然在浏览器历史中推动新的历史状态。
state: {navigationId: 2}
下面是控制台快照。
路由代码有什么问题吗?或者我缺少任何参数。
解决方案
问题是 app.module.ts 中的路由配置。由于 Angular 将默认路径路由到customComponent
,它会修改状态并且没有提供传递skipLocationChange
参数的规定,我不得不使用skipLocationChange
从 appComponent 构造函数重新路由到 customComponent ,这在我的例子中是自举的。
根据编写的代码,直接引导 customComponent 也将有所帮助。
const appRoutes: Routes = [
{
path: '',
redirectTo: "/customComponent",
pathMatch: 'full'
},
推荐阅读
- c# - 通过数据绑定 WPF/MVVM 从从数据库填充的组合框中获取所选值,以进行比较
- rest - 用于返回布尔值的 REST API 设计
- javascript - 带有通配符的 URL var
- python - 如何使用 Python 在 Linux 服务器中自动创建用户
- sql - SQL Query 以通过关系查找在 has_many 中具有某些记录的记录
- php - 如何在 php 中使用 echo 或 header 重定向页面?(在 if 条件下)
- ruby - 在渲染之前验证 ERB 模板
- visual-studio-2015 - 设置新电脑。需要构建VS2015 C++代码。我必须安装VS2015吗?
- php - 在 apache 和 php-7.3 上安装 wordpress
- node.js - 如何使用 Fetch API 忽略 SSL/TLS 验证?