vuejs / router

🚦 The official router for Vue.js
https://router.vuejs.org/
MIT License
3.77k stars 1.16k forks source link

Named components but not default component in a route with redirect to a child #2107

Closed euberdeveloper closed 6 months ago

euberdeveloper commented 6 months ago

Reproduction

https://codesandbox.io/p/sandbox/reverent-heisenberg-sw2s4d

Steps to reproduce the bug

I have a code like this:

{
          path: 'auth',
          name: 'auth',
          redirect: { name: 'login' },
          component: {
            default: AuthProxyView,
            bar: MainBar,
            menu: MainMenu
          },
          children: [
            {
              path: 'login',
              name: 'login',
              component: LoginView,
              meta: {
                title: 'login'
              }
            }
         ]
}

And I want to remove AuthProxyView, because it actually is not needed, it's just another component.

If I remove it, "AnonymousComponent" is used as default and nothing is shown instead.

Expected behavior

A stub " " component should be used by default for the default component in the route

Actual behavior

No component is passed and the main view is blank

Additional information

In the CodeSandbox, the reproduction is similar.

To make it work, uncomment // default: Stub,

posva commented 6 months ago

This is working as intended: In order to use nested routes, you will need that <RouterView />. If it's always done, you will need to add an empty component to display nothing which would be counter intuitive.

euberdeveloper commented 6 months ago

When there are not named views, this is not the current behaviour.

https://github.com/vuejs/router/releases/tag/v4.1.0 "Omitting the component/components option in routes"