angular - 在组件之间导航时保​​持路线一致

标签 angular url-routing single-page-application angular-routing

我有一个连接多个组件的路由器。每个组件都可以修改路由,以便保留其状态(复制粘贴给某人等)。

示例:

  1. /route/mycomp
  2. 玩一些领域
  3. 路线变为/route/mycomp;field=value
  4. 点击/route/othercomp,路线适应
  5. 点击/route/mycomp
  6. 路由变为route/mycomp

我希望它保留 /route/mycomp;field=value,因为组件本身没有改变。

我尝试过:

  • 更改我的 RouteReuseStrategy 实现
  • 在每个过滤器操作之后在每个组件中保存网址
  • 更改 DOM

有什么想法吗?

Angular 2.3.1。

最佳答案

您可以使用“skipLocationChange”

<a [routerLink]='xxx' skipLocationChange>next</a>

router.navigateByUrl('xxx', {skipLocationChange:true}

引用:https://angular.io/docs/ts/latest/api/router/index/NavigationExtras-interface.html

关于angular - 在组件之间导航时保​​持路线一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44132206/

相关文章:

javascript - 如何在 Angular 4 中聚焦和导航 li 元素?

angular - 限制选择下拉选项 - Angular

javascript - 具有多个页面的 PWA

vue.js - 单页应用程序路由

javascript - Angular2 路由器 : How to share a value from parent to child routes?

asp.net - 如何防止用户重新提交表单?

angular - Azure 部署 - Azure 存储中作为静态文件的 Angular 托管与使用 NodeJS 的 Web 应用程序之间有什么区别?

Angular Material不能用主题改变背景颜色

带查询参数的 Angular 路由

php - 覆盖默认路由但在必要时调用它