How to achieve multi tenant routing in angular?

2020-07-28 04:55发布

I am looking for implementing multi tenant routing mechanism where the URL should look like:

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

2条回答
【Aperson】
2楼-- · 2020-07-28 05:49

Then your routing declaration should look like this :

{ path: ':tenant', children: [
  { path: 'dashboard', component: DashboardComponent }
]}
查看更多
狗以群分
3楼-- · 2020-07-28 05:57

You'll have to declare your routing like this, where /:tenant_id will be dynamically generated.

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

You'll read the :tenant_id with the below code:

this.subscription = this.activatedRoute.queryParams.subscribe((params: Params) => {
       let tenant_id = params['tenant_id'];
       console.log(tenant_id);
});
查看更多
登录 后发表回答