【发布时间】:2019-10-02 14:02:25
【问题描述】:
我正在使用 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
},
];
【问题讨论】:
标签: angular angular6 angular7 angular7-router