Reputation: 1308
I am hoping someone can help direct me a bit.
I am busy with a Angularjs application. I am using ui-router for routing, and everything is going pretty well. I have a requirement to implement subdomains.
clients should be able to browse to the site through the normal url, but also be able to login via their subdomain, which they would be able to customise the landing page for example. Login and registration is currently working fine, so it is only to add the functionality to handling subdomains. These sub domains will also not be a static list, as companies register, they can choose a subdomain name. Dns is already configured for this, so just the Angular side left.
Any help will be great.
Thanks
Louis
Upvotes: 1
Views: 1898
Reputation: 927
Changing the sub domain will reload your site and there is nothing you can do about that. To figure out which subdomain is being accessed you can use the following code:
var segments = location.hostname.split('.');
var subdomain = segments.length>2?segments[segments.length-3].toLowerCase():null;
console.log('Subdomain is', subdomain);
Note that from your code's perspective, the sub domain will never change because if it does, it will be reloaded.
Upvotes: 2