Angular-routing:html-template 中的路由链接无法与routing-modules 中定义的路由匹配

问题描述

我有一个关于路由的问题(模块内有多条路由,延迟加载)。

假设我有 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 在哪里呢?

您也可以使用绝对路径。

如果它不起作用,请告诉我们。保重,祝你好运。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...