Skip to content

RouterView

The router view component is how route components are rendered. It is registered globally by the router plugin.

Props

PropRequiredTypeDefaultDescription
namefalsestringdefaultThe name of component to render

The name prop

The name prop is used to specify the name of the component to render. Multiple components can be defined for a single route by using the components option.

Slots

RouterView provides a default slot to render the route component. It receives the following slot scopes.

PropertyTypeDescription
routeResolvedRouteThe resolved route object for the current route
componentComponentThe component to render
rejectionRouterRejectionThe rejection object for the current route

Transitions

The default slot can be used to layer in a Vue transition if desired.

html
<router-view>
  <template #default={ component }>
    <transition name="fade">
      <component :is="Component" />
    </transition>
  </template>
</router-view>

Component Reuse

Vue will reuse components if a route change ends up rendering the same underlying component. This has advantages but can simetimes cause issues. You can avoid this by using the key attribute. Using the route.href property is a good way to generate a unique key for each route.

html
<router-view>
  <template #default={ component, route }>
    <transition name="fade" :key="route.href">
      <component :is="Component" />
    </transition>
  </template>
</router-view>