【发布时间】:2018-01-14 17:34:24
【问题描述】:
下面是我的重定向方法,它不起作用
goToProdPage() {
this.router.navigate([this.quoteId,'/cpq']);
window.location.reload();
}
但是如果我把它改成
goToProdPage() {
this.router.navigate(['./'+this.quoteId+'/cpq']);
window.location.reload();
}
然后它工作正常。但现在我无法从其他组件的激活路由中获取 url 参数(即 quoteId)。
下面是 app.module.ts 中的路由代码
const appRouter :Routes = [
{path:'login', component: loginPage},
{path:':quoteId/cpq', component: cpqPage},
{path:'', redirectTo:'/login', pathMatch:'full'},
]
【问题讨论】:
-
为什么要调用window.location.reload?
-
你为什么要构建字符串?传递数组的意义在于你可以做
this.router.navigate([this.quoteId, 'cpq'])之类的事情,让路由器自己操心细节。 -
因为在 window.location.reload 之前它只改变了 url 而不是内容。所以我强制重新加载页面,以便我可以转到重定向位置
-
@jonrsharpe 但是当我将它作为数组元素传递时它不起作用。这就是我需要你帮助的方式
-
然后显示,提供minimal reproducible example,它实际上会重现问题。
标签: javascript angular angular2-routing angular4-router