这个我花了一段时间才弄明白,所以我希望通过在 SO 的问答方式中分享解决方案来节省某人的时间。它是这样的:
我有一个 Angular8 Web 应用程序,我使用RouterModule在组件之间导航。
以下是我的路线的定义方式:
const routes: Routes = [
{ path: 'moo', component: AppMooComponent, data: { title: 'Moo Section', desc: 'Moo is the first example component.' } },
{ path: 'boo', component: AppBooComponent, data: { title: 'Boo Section', desc: 'Boo is the second example component.' } },
{ path: 'foo', component: AppFooComponent, data: { title: 'Foo Section', desc: 'Foo is the third example component.' } },
{ path: '', redirectTo: 'moo', pathMatch: 'full' …Run Code Online (Sandbox Code Playgroud)