question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add router 'prefixWith' helper

See original GitHub issue

Is 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:closed
  • Created 4 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
IlCallocommented, Oct 23, 2020

My company (Dreamonkey) released a package to address this problem https://github.com/dreamonkey/vue-routes-flattener

0reactions
IlCallocommented, Jan 7, 2020

Here I provided my implementation to automatically detect and flat logical nested routes.

It’s easy to integrate it into index.js Quasar router file

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found