我正在使用routerLink返回页面。
当前路由可能有3个级别:
myurl.com/parent
myurl.com/parent/child
myurl.com/parent/child/grandchild
另外,我有一些不同的组件,所以它不总是父级,它可以是parent1或parent2,对于child和grandchild也是如此。例如:
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
但是点击返回按钮失败了