鍍金池/ 問(wèn)答/HTML/ vue router官方教程 嵌套路由里邊的一個(gè)疑惑

vue router官方教程 嵌套路由里邊的一個(gè)疑惑

教程上說(shuō)

此時(shí),基于上面的配置,當(dāng)你訪問(wèn) /user/foo 時(shí),User 的出口是不會(huì)渲染任何東西,這是因?yàn)闆](méi)有匹配到合適的子路由。如果你想要渲染點(diǎn)什么,可以提供一個(gè) 空的 子路由:

訪問(wèn) /user/foo 時(shí),User組件是能夠渲染的,只是無(wú)法渲染作為子組件的UserProfile和UserPosts。不知道教程為什么說(shuō) “User 的出口是不會(huì)渲染任何東西”

const User = {
  template: `
    <div class="user">
      <h2>User {{ $route.params.id }}</h2>
      <router-view></router-view>
    </div>
  `
}
const router = new VueRouter({
  routes: [
    { path: '/user/:id', component: User,
      children: [
        {
          // 當(dāng) /user/:id/profile 匹配成功,
          // UserProfile 會(huì)被渲染在 User 的 <router-view> 中
          path: 'profile',
          component: UserProfile
        },
        {
          // 當(dāng) /user/:id/posts 匹配成功
          // UserPosts 會(huì)被渲染在 User 的 <router-view> 中
          path: 'posts',
          component: UserPosts
        }
      ]
    }
  ]
})
回答
編輯回答
空痕

不知道教程為什么說(shuō) “User 的出口是不會(huì)渲染任何東西”
這句話出口應(yīng)該是指 User中的<router-view></router-view>
在訪問(wèn) /user/foo 時(shí)路徑未匹配成功 因?yàn)?code>foo 變成params參數(shù)
所以 User中的<router-view></router-view> 未渲染任何東西

2017年2月25日 20:15
編輯回答
落殤

意思是如果直接訪問(wèn)二級(jí)路徑的話 父路由組件component對(duì)應(yīng)的應(yīng)該是一個(gè)空的頁(yè)面 這個(gè)頁(yè)面里只有一個(gè)

<template>
    <router-view></router-view>
</template>

圖片描述

2018年1月17日 11:01