Angular 带辅助路线的角度6材质选项卡导航
我设置了两个路由器,一个是延迟加载的,用于访问父路由的子路由。 这里的目标是拥有一些基本上完全不相关的页面的高级路由,其中一些页面有自己的子例程,其中选项卡用于导航 子路线:Angular 带辅助路线的角度6材质选项卡导航,angular,angular-material,Angular,Angular Material,我设置了两个路由器,一个是延迟加载的,用于访问父路由的子路由。 这里的目标是拥有一些基本上完全不相关的页面的高级路由,其中一些页面有自己的子例程,其中选项卡用于导航 子路线: const dashboardRoutes = [ {path: '', redirectTo: 'dashboard', pathMatch: 'full'}, {path: 'dashboard', component: DashboardContainerComponent, children:[
const dashboardRoutes = [
{path: '', redirectTo: 'dashboard', pathMatch: 'full'},
{path: 'dashboard', component: DashboardContainerComponent, children:[
{path: 'home', component: DashboardComponent, outlet: 'dashboard'},
]
];
@NgModule({
imports: [
RouterModule.forChild(dashboardRoutes)
],
exports: [RouterModule]
})
export class DashboardRoutingModule { }
父路由:
const routes: Routes = [
{path: '', redirectTo: 'dashboard', pathMatch: 'full'},
{path: 'dashboard', loadChildren: '../dashboard/dashboard.module#DashboardModule'}
]
@NgModule({
imports :[
RouterModule.forRoot(routes, {useHash: true})
],
exports: [
RouterModule
]
})
export class RoutingModuleModule { }
当我在地址栏中键入路径时,这可以正常工作:
http://localhost:4200/#/dashboard/dashboard/(仪表板:主页)
但是,当我尝试使用“材质”选项卡导航时,我得到:Error:无法匹配任何路线。URL段:“dashboard/dashboard/%28 dashboard:home%29”
在我的组件中,我有:
navlinks = [
{path: '(dashboard:home)', label: 'Home'}
]
html:
{{link.label}
这看起来基本上是正确的,然而,在某一点上,括号可能会被替换
我尝试了几种变体,例如没有括号、斜杠等,但都没有产生预期的结果
有人对我的链接列表中的值有什么建议吗?试试:
{path:'./dashboard/home',标签:'home'}
检查一下:我想你也需要重写路由路径。为什么您希望仪表板
在URL上出现这么多次?我不一定需要仪表板出现这么多次,但是,这不应该影响它是否有效。不过谢谢你的建议,我会考虑简化路线。关于第一条注释,它向我提供了一个类似的错误:无法匹配任何路由。URL段:“dashboard/dashboard/dashboard/home”
注意,这些是辅助路由,所以据我所知,您需要使用(x:y)格式。
<nav mat-tab-nav-bar mat-align-tabs="center">
<a mat-tab-link
*ngFor="let link of navlinks"
[routerLink]="link.path"
routerLinkActive #rla="routerLinkActive"
[routerLinkActiveOptions]="{exact: true}"
[active]="rla.isActive">
{{link.label}}
</a>
</nav>
<router-outlet name="dashboard"></router-outlet>