如何以角度实现多租户路由? [英] How to achieve multi tenant routing in angular?

查看:30
本文介绍了如何以角度实现多租户路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

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

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 }
    ]
}

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

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);
});

这篇关于如何以角度实现多租户路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆