gpt4 book ai didi

Angular 8 默认路由

转载 作者:行者123 更新时间:2023-12-04 23:48:31 25 4
gpt4 key购买 nike

我有一个运行 Angular 8.2 的应用程序。路由运行良好,默认路由除外。

当去website.com我想被重定向到 website.com/sign-in
应用程序路由.模块

const routes: Routes = [
{
path: '',
redirectTo: 'sign-in',
pathMatch: 'full'
},
{
path: '',
component: PublicLayoutComponent,
data: { title: 'Public Views' },
children: PUBLIC_ROUTES
},
{
path: '',
component: PrivateLayoutComponent,
data: { title: 'Private Views' },
children: PRIVATE_ROUTES
},
];

公共(public)路由模块
export const PUBLIC_ROUTES: Routes = [
{
path: "sign-in",
loadChildren: () =>
import('../features/sign-in/sign-in.module').then(
m => m.SignInModule
)
}
];

私有(private)路由模块
export const PRIVATE_ROUTES: Routes = [
{
path: "dashboard",
loadChildren: () =>
import('../features/dashboard/dashboard.module').then(
m => m.DashboardModule
)
}
];

我也尝试将其添加到 应用程序路由.模块
{
path: '**',
redirectTo: 'sign-in',
pathMatch: 'full'
},

编辑:

我所有的路线都有效。当去 website.com/sign-in , Angular 看 应用程序路由.模块然后在子路线上找到路线。如果我添加
{
path: '**',
redirectTo: 'sign-in',
pathMatch: 'full'
}

公共(public)路由模块 ,除空白之外的任何内容都将重定向到登录。 website.com/jdjhjdfjd将转到我的登录页面,但 website.com将不会。

最佳答案

可能是因为您尚未定义登录路线

const routes: Routes = [
{
path: '',
redirectTo: 'sign-in',
pathMatch: 'full'
},
...
{
path: 'sign-in',
component: SignInComponent,
data: { title: 'Private Views' },
},
];

关于Angular 8 默认路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57931364/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com