我只是学习nativescript,angular和打字稿 . 我正在使用模拟器开发iOS . 我的路由配置如下(从NativeScript检查器复制粘贴):

config: Array (7)
0{path: "filtered/:topic/:queryText", component: function}
1{path: "abstract/:id", component: function}
2{path: "session/:id", component: function}
3{path: "details/:id", component: function}
4{path: "home", component: function}
5{path: "", redirectTo: "home", pathMatch: "full"}
6{path: "**", redirectTo: "home"}

homedetails 的路由在 home.component 中使用此代码:

showDetails(e){
    console.log(e.index);
    this.router.navigate(["details", e.index]);
}

这在大多数情况下都有效,但是当我第一次导航到 filtered 组件然后使用“返回”按钮返回时,可靠地失败 . 触发 showDetails 函数,记录 e.index 的正确值,但应用程序未路由到 details ; home 页面根本没有变化(但我仍然可以从 home 页面导航到其他页面) .

我的问题是,我应该如何解决这个问题?我可以在检查器中看到 this.router 对象,但它猜测我应该尝试找出当 showDetails 函数按预期工作时 this.router 的样子,以及当 showDetails 不再有效时它会如何变化 . 但是我应该关注哪些属性?或者我应该看别的东西?

非常感谢任何提示或指导 .

更新:每当我导航到两个以上的其他页面时,问题就出现了,例如,如果我只是导航到 filtered ,它不会发生,但是如果从 filtered 导航到 abstract ,然后使用后退按钮两次,它总是会发生 . 如果首先导航到 session 然后 abstract ,然后返回 home ,则相同 .

更新2:这里的答案对于调试路由非常有用:

How to detect a route change in Angular 2?

更新3:我明白了 . 我的路线中的一个参数有时是空的,导致带有双斜线的网址: /filtered//search-term . Angular似乎不喜欢这样 .