Add router 'prefixWith' helper
See original GitHub issueIs your feature request related to a problem? Please describe. When using vue router, it’s currently not possible to logically group multiple routes with the same prefix while keeping them at the same router-outlet level of ther others.
Example
// This won't work
const routes = [
{
path: '/',
component: () => import('layouts/frame.vue'),
children: [
{ path: '', component: () => import('pages/home.vue') },
{ path: 'home', component: () => import('pages/home.vue') },
{
path: 'products',
children: [
{ path: '', component: () => import('pages/products.vue') },
{
path: 'type-a',
component: () => import('pages/product-type-a.vue'),
},
{
path: 'type-b',
component: () => import('pages/product-type-b.vue'),
}
],
},
{ path: 'company', component: () => import('pages/company.vue') }
],
},
];
// This will work, but you have to repeat the parent path name
const routes = [
{
path: '/',
component: () => import('layouts/frame.vue'),
children: [
{ path: '', component: () => import('pages/home.vue') },
{ path: 'home', component: () => import('pages/home.vue') },
{ path: 'products', component: () => import('pages/products.vue') },
{ path: 'products/type-a', component: () => import('pages/product-type-a.vue') },
{ path: 'products/type-b', component: () => import('pages/product-type-b.vue') },
{ path: 'company', component: () => import('pages/company.vue') }
],
},
];
Describe the solution you’d like
Current suggested workaround is to create a prefixWith helper, which would already be enough.
Another step would be to detect when component isn’t provided on the parent route and automatically flat it, or add a logical property which serve the same purpose (detect routes to be flattened) but is more explicit about what’s going to happen.
Describe alternatives you’ve considered Adding a notice on the docs linking to the proposed solution from Evan You.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Adding prefix to a named route helper under namespace
I want to add "new" prefix to this named route and make it look like new_admin_post_path and I don't want to use resources...
Read more >Route prefix not added when using route helper
I create a route group with a prefix {$tenant} inside RouteServiceProvider: Route::prefix('/{tenant}') ->middleware(['web', 'tenant', ...
Read more >Add prefix option to Router.Helpers · Issue #2874
I have two Routers in my application: The parent one: defmodule Router do use Phoenix.Router forward ...
Read more >Route Prefix in ASP.NET MVC Attribute Routing
First, add a class file with the name “Teacher.cs” within the Models Folder. To do so right-click on the Models folder, and then...
Read more >Routing to controller actions in ASP.NET Core
Learn how ASP.NET Core MVC uses Routing Middleware to match URLs of incoming requests and map them to actions.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

My company (Dreamonkey) released a package to address this problem https://github.com/dreamonkey/vue-routes-flattener
Here I provided my implementation to automatically detect and flat logical nested routes.
It’s easy to integrate it into
index.jsQuasar router file