这个问题可能是因为在应用中定义了多个路由组件,并且在其中一个组件中同时使用了router-outlet和相对路径导航。要解决此问题,可以尝试在路由定义中添加{initialNavigation:'enabled'}选项或将base href标签添加到index.html文件中。
代码示例:
1.在路由定义中添加{initialNavigation:'enabled'}选项
const routes: Routes = [ { path: '', component: HomeComponent, pathMatch: 'full', data: { title: 'Home' } }, { path: 'about', component: AboutComponent, data: { title: 'About' } }, // ... ];
@NgModule({ imports: [RouterModule.forRoot(routes, { initialNavigation: 'enabled' })], exports: [RouterModule] }) export class AppRoutingModule { }
2.将base href标签添加到index.html文件中