如何在 Angular 2(路由器 3)中处理租户子域 [英] How to handle tenant subdomains in Angular 2 (router 3)

查看:24
本文介绍了如何在 Angular 2(路由器 3)中处理租户子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在 Angular 2(RC6,路由器 3.0)中设置tenant.app.com

Trying to get tenant.app.com setup in Angular 2 (RC6, Router 3.0)

是否有关于如何执行此操作的文档?我看到的几乎所有内容都以 base url =/开头,然后从 base url 解析 url.

Is there any documentation around how to do this? Almost everything I've seen starts with a base url = / and then parses the url from the base url.

我需要为非登录用户提供 www 版本,然后为所有登录用户提供租户驱动的子域

I need to have a www version for the non-signedin user and then tenant driven subdomains for all loggedin users

推荐答案

我想我有一个有效的方法.getSubdomain() 允许我在 NgInit() 上查询 app.component.ts 中的子域,我可以使用它来根据绑定到子域的租户 ID 来确定用户的登录范围

I think I have an approach that's working. getSubdomain() allows me to query the subdomain in app.component.ts on NgInit() and I can use that to scope the sign in for the user against a tenant_id tied to the subdomain

getSubdomain() {
  const domain = window.location.hostname;
  if (domain.indexOf('.') < 0 || 
    domain.split('.')[0] === 'example' || domain.split('.')[0] === 'lvh' || domain.split('.')[0] === 'www') {
    this.subdomain = '';
  } else {
    this.subdomain = domain.split('.')[0];
  }
  console.log('subdomain', this.subdomain);
}

这篇关于如何在 Angular 2(路由器 3)中处理租户子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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