Skip to content

Allow child routes to target views in all ancestorsΒ #2324

Closed
@backbone87

Description

@backbone87

What problem does this feature solve?

Lets say i have a simple CRUD UI with a listing and a details view.
The route config would look something like this:

    {
      path: '/users',
      name: 'Users',
      components: {
        navigation: Navigation,
        toolbar: Toolbar,
      },
      children: [
        {
          path: '',
          name: 'UserList',
          components: {
            default: UserList,
          },
        },
        {
          path: ':userId',
          name: 'UserDetails',
          components: {
            default: UserDetails,
          },
        },
      ],
    }

Also my App.vue template would look similar to this:

div
  .toolbar
    router-view(name="toolbar")
  .navigation
    router-view(name="navigation")
  .content
    router-view

This does not work as expected because the child routes can only target views inside either parents currently rendered views.

The first i tried was to just drop in a view into the parents default view:

    {
      name: 'Users',
      components: {
        navigation: Navigation,
        toolbar: Toolbar,
        default: Vue.component('router-view')
      },
    },

But this leads to infinite recursion with maximum stack size error.

The next thing i tried was flattening the routes and it worked, but is much more verbose to configure.

Basically the route nesting must follow your component structure insteadof a more "natural" approach like navigation structure (where is the visitor?), the url structure (whats the name of the currently visited location?) or config structure (which routes share commen settings?). The URL structure can already be freely set, because you can use absolute paths in nested routes. But its a hassle to structure the route config to follow navigation structure without implying a specific component structure.

What does the proposed API look like?

A new config option could be provided to switch the view targeting behavior. This will maintain BC and allows more versatility when structuring the route config

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions