Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subdomain Routing in vuejs #233

Closed
kamuran21 opened this issue Nov 12, 2015 · 8 comments
Closed

Subdomain Routing in vuejs #233

kamuran21 opened this issue Nov 12, 2015 · 8 comments

Comments

@kamuran21
Copy link

Hi everybody. Our first vuejs project next to end. But I faced a problem with routing subdomains. Users can use their user names as subdomain to show their contact informations for example : http://kamuransonecek.exlample.com

how can I detect username from subdomain to routing the site pages?

'http://:userName.example.com': {
    component: require('./views/userinfo')
  },

This codes not work as I espected. I wait for your helps. Thanks

@nicolasparada
Copy link

If this is posible I'll be very surprised.

@aliuygur
Copy link

+1

@yyx990803
Copy link
Member

You shouldn't need vue-router to get this. Just use window.location.host and use regex to extract it yourself.

@kamuran21
Copy link
Author

My solution is this :

'/': {
    component: function() {
      var reg = new RegExp("www|sitename|test|localhost:8000");
      var parts = window.location.host.split(".");
      return reg.test(parts[0]) ? require('./views/home') : require('./views/subdomain');
    }()
  },

I hope it will be helpful for others.

@zolotov88
Copy link

What about SSR? How to get domain name on server?

@wernerm
Copy link

wernerm commented Mar 8, 2018

For SSR see nuxt/nuxt#2378

@Austio
Copy link

Austio commented Mar 8, 2018

@zolotov88 if you are using ssr you will only want use window when it is available and if you are using express use the 'req' param of your middleware to get the subdomain on first request and the use that to match routes with.

@cve
Copy link

cve commented Oct 18, 2018

in nuxt with dev server I'm getting window is not defined even if I'm using !process.server. How to handle that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants