我正在编写一个具有以下结构的模拟电子商务应用程序:
- 应用程序
- 授权
- 登录页面
- 注册页面
- auth-routing.module.ts
const routes: Routes = [ { path: 'signup', component: SignUpPage, }, { path: 'signin', component: SignInPage, }, ]; - auth.module.ts
- 行政
- 根页面
- 管理员路由.module.ts
const routes: Routes = [ { path: 'admin', component: RootPage, children: [ // ... ], }, ]; - admin.modules.ts
- 顾客
- 根页面
- 目录页
- 结帐页面
- 感谢页面
- 客户路由.module.ts
const routes: Routes = [ { path: 'customer', component: RootPage, children: [ { path: 'catalog/:categoryId', component: CatalogPage }, { path: 'checkout', component: CheckOutPage }, { path: 'thankyou', component: ThankYouPage }, ], }, ]; - 客户.module.ts
- 网页未找到
- 应用程序路由.module.ts
const routes: Routes = [ { path: '**', component: NotFoundPage }, ]; - app.module.ts
- app.component.html
- app.component.css
- 授权
基本工作流程应该如下:
- 用户导航到根路径
/。 - 应用程序检测到他们没有登录,因此将他们重定向到
/signin. - 他们输入他们的凭据并按登录。
- 如果认证成功,
- 如果用户是管理员,他们会被重定向到
/admin.admin-router.module.ts将它们重定向到/admin.
- 如果用户是客户,他们会被重定向到
/customer.customer-router.module.ts将它们重定向到/customer/catalog/<default category ID>.- 他们将一些产品放入购物车并继续进行
/customer/checkout。 - 他们下订单并被重定向到
/customer/thankyou.
- 如果用户是管理员,他们会被重定向到
我不确定的是如何在成功登录后完成重定向。显然,它必须分两个阶段完成:首先到一些公共路径,例如/然后根据用户的角色要么到/customer要么到。/admin第二阶段可能需要由 处理app-routing.module.ts,可能需要使用警卫,但我不确定该怎么做。
编辑 (2021-04-20)
问题可以总结如下:
我需要的是一种方法(最好是声明性的),/根据其状态将应用程序从以下路径之一重定向到:
| 状态 | 小路 |
|---|---|
| 登出 | /auth |
| 以客户身份登录 | /customer |
| 以管理员身份登录 | /admin |