问题描述
假设我有 2 个模块
1-app.routing.module.ts 2-user.management.routing.module.ts
const appRoutes: Routes = [
{ path: '',redirectTo: '/login',pathMatch: 'full' },{ path: 'login',loadChildren: () => import('../app/user.management/user.management.module')
.then(m => m.UserManagementModule) }
]
@NgModule({
imports: [RouterModule.forRoot(appRoutes)],exports: [RouterModule]
})
export class AppRoutingModules {}
const userManagementRouting: Routes = [
{ path: '',component: LoginComponent },{ path: 'forgot-password',component: ForgotPasswordComponent }
];
@NgModule({
imports: [RouterModule.forChild(userManagementRouting)],exports: [RouterModule]
})
export class UserManagementRoutingModule { }
当我使用“ng serve”运行应用程序时,它按预期工作。我添加了一个链接,如
<a class="btn btn-link" routerLink="/forgot-password">Forgot Password </a>
"Error: Uncaught (in promise): Error: cannot match any routes. URL segment: 'forgot-password'"
"Cannot match any routes. URL segment: 'forgot password"
解决方法
如果 R. Richards 的建议不起作用,请尝试
routerLink=['/forgot-password']
或
routerLink=['/login/forgot-password']
请注意,您使用的是相对路径。那么这个 Html-template 在哪里呢?
您也可以使用绝对路径。
如果它不起作用,请告诉我们。保重,祝你好运。