用auth0s authguard配置角路由
我想配置嵌套的懒惰加载路线,只有在用户登录时才可用。身份验证可与Auth0s一起使用,并且是相应的authguard。 因此,例如,我的路线看起来像这样:
const routes: Routes = [
{
path: ':id',
children: [
{
path: '',
children: [ {
path: 'first-component',
loadChildren: () => import('./first-component.module').then((m) => m.FirstComponentModule),
canLoad: [AuthGuard],
},
{
path: 'second-component',
loadChildren: () => import('./second-component.module').then((m) => m.SecondComponentModule),
canLoad: [AuthGuard],
},
],
},
{
path: '',
pathMatch: 'full',
redirectTo: 'first-component',
},
],
},
{
path: ':id',
redirectTo: ':id',
pathMatch: 'full',
},
{
path: '**',
component: PageNotFoundComponent,
},
];
:ID < /code> paramter是需要的,应该保留在URL中,以便看起来像这样:
my-app/ID123/first-component
但是身份验证我被重定向到 /id123-&gt;找不到
我想念什么?
I would like to configure my lazy loaded routes nested, which are only available if the users is logged in. Authentication works with Auth0s and it's corresponding AuthGuard.
So for example my routes look like this :
const routes: Routes = [
{
path: ':id',
children: [
{
path: '',
children: [ {
path: 'first-component',
loadChildren: () => import('./first-component.module').then((m) => m.FirstComponentModule),
canLoad: [AuthGuard],
},
{
path: 'second-component',
loadChildren: () => import('./second-component.module').then((m) => m.SecondComponentModule),
canLoad: [AuthGuard],
},
],
},
{
path: '',
pathMatch: 'full',
redirectTo: 'first-component',
},
],
},
{
path: ':id',
redirectTo: ':id',
pathMatch: 'full',
},
{
path: '**',
component: PageNotFoundComponent,
},
];
the :id
paramter is needed, and should stay in the url so it should look like this:
my-app/ID123/first-component
But authentication I am redirected to /ID123 -> not found
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
警卫不应该是问题。
您可以尝试此简化的路由配置:
如果此配置不起作用,请发送您的父路由配置。
这些问题可能存在。
The guard should not be the problem.
You can try this simplified routes configuration:
If this configuration does not work, please send your parent routing configuration.
It is possible that the issues is there.