angular - 角度路由不起作用,它将我重定向到基本网址
问题描述
我正在尝试使用angular router
从我的页面导航。
我有一个button
点击,我正在导航到其他页面。
我目前的网址是:http://localhost:4200/user/12345567
。从这里我点击按钮导航离开
这是我的button
代码:
leaveArea(){
this.router.navigate([ 'account', 'dashboard'], {relativeTo: this.route});
}
我想导航到http://localhost:4200/account/dashboard
点击。
但相反,我被导航到http://localhost:4200
. 一瞬间(可能是一毫秒甚至更短),我确实看到了 url,就像http://localhost:4200/account/dashboard
它导航到http://localhost:4200
. 路由逻辑有问题吗?
编辑
我正在添加routeTrace
结果:
编辑
这是我的路由文件:
const appRoutes: Routes = [
{ path: "", component: HomeComponent },
{ path: "account/dashboard", component: AccountDashboardComponent},
{
path: "user/:id", component: UserComponent
}
];
@NgModule({
imports: [RouterModule.forRoot(appRoutes, { enableTracing: true })],
exports: [RouterModule]
})
export class AppRoutingModule {}
解决方案
只需尝试router.navigateByUrl
像这样使用 -
leaveArea(){
this.router.navigateByUrl('/account/dashboard');
}
PS:通过附加/
在字符串的开头将考虑从根级别路由。
推荐阅读
- javascript - 表单提交刷新页面
- git - 为什么 Git 中的 040000 意思是目录?
- angular - 如何在 html-webpack-plugin 中获取块 {scripts}
- julia - 如何在 Julia 中有效地初始化巨大的稀疏数组?
- python - 我已经完成了“!pip install pandas”,但 Jupyter 仍然找不到它
- android - 如何使用 geckoview 渲染 html?
- kubernetes - 删除服务后如何清理kubernetes中的数据库?
- html - 我的提交和清除按钮在我的表单中不起作用
- javascript - 如何修复tenserflow.js中的类似预测
- unity3d - Unity在相机移动期间显示瓷砖的边界