我创建了一个带有父路由的路由器,其中包含一个 id 和子路由。问题是,当我想使用选项卡在我的子路线下导航时,出现错误:
错误:无法匹配任何路由。 URL 段:'tabs/user/1/overview'。 错误:无法匹配任何路由。 URL 段:'tabs/user/1/overview'。
用户路由器:
export const routes: Routes = [
{
path: 'user/:id',
component: UserdetailComponent,
resolve: {
test: dataResolver,
},
children: [
{ path: '', redirectTo: 'overview', pathMatch: 'full' },
{ path: '', redirectTo: 'overview', pathMatch: 'full' },
{ path: 'overview', loadChildren: () =>
import('./overview-module/overview.module').then(
m => m.OverviewModule
)
},
{ path: 'contact', loadChildren: () =>
import('./contact-module/contact.module').then(
m => m.ContactModule
)
},
]}];
export const UserModule: ModuleWithProviders = RouterModule.forChild(
routes
);
概览路由:
@NgModule({
declarations: [OverviewComponent],
imports: [
CoreModule,
RouterModule.forChild([
{
path: '',
component: OverviewComponent,
}
]),
],
exports: [OverviewComponent]
})
导出类概览模块{}
和我的标签的一个按钮:
<ion-button
size="small"
fill="clear"
color="text"
[routerLink]="[userId, 'overview']"
<块引用>
是不是因为我的子路由连接到一个有自己路由器的模块?请问我该如何解决我的问题?
编辑:我尝试过使用组件,并通过在每条道路上添加我的 :userId,我可以在道路上导航,但我被卡住了。我猜它进入了子路由并且找不到其他路由......
谢谢
答案 0 :(得分:2)
我认为您需要将路由器链接更改为
[routerLink]="['/tabs/user', userId, 'overview']"
我们需要先指定父路径,然后才能添加子路径。让我知道它是否有效。