Search code examples
subdomainvue.jsvue-router

Vue.js: vue-router subdomains


The vue-router documentation does not address this topic.

Perhaps my expectation that vue-router could handle this illustrates a fundamental misunderstanding of mine of how subdomains operate.

Could this be handled by vue-router, and if so, how, and if not, why not?


Solution

  • Nope, it's not possible.

    vue-router uses history.pushState, which doesn't allow you to change the origin. Quote from the docs:

    The new URL must be of the same origin as the current URL; otherwise, pushState() will throw an exception.

    In other words - vue-router is a client-side router and you can't change the subdomain on the client-side (in the browser) without reloading the page.