posva / unplugin-vue-router

Next Generation file based typed routing for Vue Router
https://uvr.esm.is
MIT License
1.62k stars 79 forks source link

Allow creating multiple router instances #148

Open DellanX opened 1 year ago

DellanX commented 1 year ago

This package is amazing, though I think I may have a complicated use case to mess things up.

As of now, I have a laravel project with 3 subdomains, each has different routes available to them:

  1. core website with login and user management
  2. chat subdomain with pages for sending messages
  3. utility subdomain with pages for a user's calendar management.

I need to be able to generate different route configurations for the subdomains independent of each other.

Excess information

For the purpose of development, I used this plugin with routesFolder to populate all 3 sets on all 3 subdomains. The issue is that the API doesn't serve routes outside of the subdomain. (e.g. calendar API doesn't work on chat pages). Fine for development; however, for production a 404 should page appear instead.

What I'd prefer to be able to do, is add a route folder during runtime, so that each entry point only needs to add its specific routes. Or even better, to be able to load this in the vite config somehow? (maybe through output.plugins?)

That being said, I can't imagine how this could be added to the output.plugins setting in a way that doesn't destructively merge. As of now, if I try this, vite throws an error stating that vue-router/auto does not exist

posva commented 1 year ago

Thanks!

Maybe this could be possible by allowing the plugin to be instantiated multiple times and exposing each of them via different module vue-router/auto-1 etc

DellanX commented 1 year ago

Oooo, yes that's actually a great idea in my opinion.

Though, preferably we'd be able to add an alias such as: "vue-router/auto-chat"