在Angular中,要使子路由不追加到URL中,可以使用以下解决方法:
pathMatch: 'prefix'
。这将使子路由的路径被视为父级路由的前缀,而不是追加到URL中。const routes: Routes = [
{
path: 'parent',
component: ParentComponent,
children: [
{
path: 'child',
component: ChildComponent
}
]
}
];
''
),这将使父级路由成为默认路由,并且子路由不会追加到URL中。const routes: Routes = [
{
path: '',
component: ParentComponent,
children: [
{
path: 'child',
component: ChildComponent
}
]
}
];
这样,当访问/parent
时,父级组件将被加载,并且不会追加子路由到URL中。而当访问/parent/child
时,父级组件和子组件将被加载,并且子路由会追加到URL中。