how to route using subdomain in angular2?

匆匆过客 提交于 2019-12-05 04:04:19

This can easily be done, but not with Angular (or any other JavaScript router for that matter). Routing to a sub-domain requires the server to help out. You need to set up user1 and user2 as sub-domains and then in your default document, route to either based on whatever you rules are.

You Angular app will then reside at either address, so there will be one at http://user1.example.com/index.html and another at http://user2.example.com. It could be the same app as well.

For an all-Angular solution, you should simply change your scheme to use http://example.com/user1.

There is one more reason why the latter URL scheme may be better for you. If you self-host, you can create sub-domains to your heart's content. If, however, you're using shared hosting, there is a pretty high likelihood that you'll be limited to the number of sub-domains you can use - it may be as few as two.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!