我正在使用 Angular 路由来浏览组件。当用户登录时,他们被导航到dashboard/:id
然后他们看到dashboard/123/projects
等等。问题是,当用户/dashboard
仅导航到时,我想/dashboard/:id
默认将它们重定向到。但是当我这样做时:{ path:"dashboard", redirectTo:"dashboard/:id/projects", pathMatch:"full"}
它通过一个错误说:id
未定义,并且我无法导航到从/dashboard
当前用户登录/dashboard/123/projects
。
我的 Routes.modules.ts 代码
const routes: Routes = [{
path: "",
redirectTo: "/login",
pathMatch: "full"
},
{
path: "login",
component: LoginComponent
},
{
path: "register",
component: RegisterComponent
},
//the problem goes here
{
path: "dashboard",
redirectTo: "", //How to redirect to dashboard/:id ?
pathMatch: "full"
},
{
path: "dashboard/:id",
component: DashboardComponent,
children: [{
path: "",
redirectTo: "projects",
pathMatch: "full"
},
{
path: "projects",
component: ProjectsComponent
},
{
path: "archived",
component: ArchivedProjectsComponent
},
{
path: "projects/:id",
component: SingleProjectComponent,
children: [{
path: "",
redirectTo: "plans",
pathMatch: "full"
},
{
path: "plans",
component: PlansComponent
},
{
path: "tasks",
component: TasksComponent
},
{
path: "photos",
component: PhotosComponent
},
{
path: "files",
component: FilesComponent
},
{
path: "people",
component: PeopleComponent
},
{
path: "settings",
component: SettingsComponent
},
{
path: "trash",
component: TrashComponent
},
{
path: "**",
redirectTo: "plans",
pathMatch: "full"
}
]
},
{
path: "**",
redirectTo: "projects",
pathMatch: "full"
}
]
},
{
path: "**",
component: PageNotFoundComponent
},
];