angular如何实现多租户路由?

How to achieve multi tenant routing in angular?

我正在寻找实施多租户路由机制,其中 URL 应该如下所示:

myapp.com/tenant-1/dashboard, 
myapp.com/tenant-2/dashboard.

然后你的路由声明应该是这样的:

{ path: ':tenant', children: [
  { path: 'dashboard', component: DashboardComponent }
]}

您必须像这样声明路由,其中​​ /:tenant_id 将动态生成。

{ 
    path: 'tenant/:tenant_id', 
    children: [
       { path: 'dashboard', component: DashboardComponent },
       { path: 'SomeOther', component: SomeOtherComponent }
    ]
}

您将使用以下代码阅读:tenant_id:

this.subscription = this.activatedRoute.queryParams.subscribe((params: Params) => {
       let tenant_id = params['tenant_id'];
       console.log(tenant_id);
});