routerLink Angular中的布线不正确



我对这个路由感到困惑。

应用程序路由文件

const routes: Routes = [
{
path: '',
redirectTo: 'main',
pathMatch: 'full'
},
{
path: 'main',
loadChildren: () =>
import('./modules/main/main.module').then(m => m.MainModule)
},
{
path: 'auth',
loadChildren: () =>
import('./modules/auth/auth.module').then(m => m.AuthModule)
},
{
path: '', component: HomeMenuComponent, children: [
],
}];

文件身份验证路由

const routes: Routes = [
{
path: '',
redirectTo: 'login',
pathMatch: 'full'
},
{
path: '',
children: [
{
path: 'login',
component: LoginComponent
},
{
path: 'register',
component: RegisterComponent
}
]
}
];

但当在模板login-component.html中时,我正试图遵循以下链接:

<span class="link" routerLink="register" routerLinkActive="active-link">Зарегистрироваться</span>

它把我送到这个地址:

auth/login/register

为什么会发生这种情况?一方面,没错,我处于身份验证/登录级别。但另一方面,当我看到其他例子时,它们不知何故出现在这样的地址。只是我不明白我需要补充什么。

来源https://angular.io/api/router/RouterLink

"如果第一个分段以/开头,路由器将从应用程序的根目录查找路由。

如果第一段以./开始,或者不是以斜线开头,路由器会查找当前激活路由的子路由">

当您使用routerLink='register'时,您可能处于auth/login,根据上面的引用,它将带您进行身份验证/登录/注册

尝试routerLink="/auth/register"

最新更新