【发布时间】:2018-07-11 14:47:57
【问题描述】:
我正在使用 routerLink 返回我的页面。
当前路线可以有 3 个级别:
myurl.com/parent
myurl.com/parent/child
myurl.com/parent/child/grandchild
另外,我有一些不同的组件,所以它不会总是父母,它可以是父母1,也可以是父母2,也适用于子孙,例如:
myurl.com/parent2/child1/grandchild2
我想要的总是去上一层,例如:
myurl.com/parent/child/grandchild -> myurl.com/parent/grandchild
我所做的是:
<button [routerLink]="['../'']">
back
</button>
但它总是导航到“myurl.com”
我该如何解决?
正如一些用户所建议的,我正在分享我的路由配置:
在 app.routing.ts 中:
const APP_ROUTES: Routes = [
{
path: '',
canActivate: [LoggedInGuard],
children: [
{path: '', redirectTo: '/mainPage', pathMatch: 'full'},
{path: 'parent', loadChildren: 'app/parent/parend.module#ParentModule'
]},
{path: '**', redirectTo: ''}
];
在 parent.routing.ts 中:
const PARENT_ROUTES: Routes = [
{path: '', component: ParentComponent},
{path: ':id', component: ChildComponent},
];
如果在我写的浏览器中:
myurl.com/parent -> it works
但点击后退按钮失败
【问题讨论】:
-
stackoverflow.com/questions/37196882/… 也许这会对你有所帮助
-
谢谢,我已经读过这个但没有帮助我:(
-
你能分享你的路由配置吗?
标签: angular angular5 angular-routerlink