実際のアプリケーション・インターフェース、一緒にネストされたコンポーネントの一般的組み合わせ。同様に、特定の構造動的経路に応じて、各セグメントのURLは、例えば、ネストされたコンポーネントの層に対応することができます。
/user/foo/profile /user/foo/posts
+------------------+ +-----------------+
| User | | User |
| +--------------+ | | +-------------+ |
| | Profile | | +------------> | | Posts | |
| | | | | | | |
| +--------------+ | | +-------------+ |
+------------------+ +-----------------+
では vue-router
、ネストされたルーティング設定を使用するには、単にこの関係を表現することができます。
そして、祭りはアプリを作成しました:
<div id="app"> <router-view></router-view> </div>
const User = {
template: '<div>User {{ $route.params.id }}</div>' } const router = new VueRouter({ routes: [ { path: '/user/:id', component: User } ] })
ここ <router-view>
では、最も高度なルーティングに一致するようにコンポーネントをレンダリングし、トップの輸出です。同様に、成分は、それ自体がネストを含むレンダリングすることができます <router-view>
。例えば、内 User
テンプレート成分を加えます <router-view>
。
const User = {
template: ` <div class="user"> <h2>User {{ $route.params.id }}</h2> <router-view></router-view> </div> ` }
ネストされたコンセントにコンポーネントをレンダリングするには、必要である VueRouter
パラメータを使用して children
設定を:
const router = new VueRouter({ routes: [ { path: '/user/:id', component: User, children: [ { // 当 /user/:id/profile 匹配成功, // UserProfile 会被渲染在 User 的 <router-view> 中 path: 'profile', component: UserProfile }, { // 当 /user/:id/posts 匹配成功 // UserPosts 会被渲染在 User 的 <router-view> 中 path: 'posts', component: UserPosts } ] } ] })
注意を払う /
、それがルート・パスの始まりとして扱われますネストされたパス。これは、ネストされた設定しなくても、あなたの完全な使用ネストされたパスコンポーネントを可能にします。
あなたはわかりますchildren
設定は似ている routes
設定配列をルーティングの同じ構成なので、あなたが巣多層配線をすることができます。
この時点で、上記の構成に基づいて、あなたが訪問したときに /user/foo
、User
適切なサブルートに一致するものがないため、輸出は何も表示されません、それはです。あなたが何かをレンダリングしたい場合は、空のサブルートを提供することができます。
const router = new VueRouter({ routes: [ { path: '/user/:id', component: User, children: [ // 当 /user/:id 匹配成功, // UserHome 会被渲染在 User 的 <router-view> 中 { path: '', component: UserHome }, // ...其他子路由 ] } ] })
http://www.mulanzhichun.cn
http://www.kemaisii.cn
http://www.biyuzunn.cn
http://www.huianters.cn
http://www.khoty.cn
http://www.burkepoohs.cn
http://www.eternelle.cn
http://www.jessiejanes.cn
http://www.yajuxuan.cn
http://www.nodonkg.cn
http://www.dengyuandi.cn
http://www.yurunyipinn.cn
http://www.niudangjiaa.cn
http://www.feikeshoubiaoo.cn
http://www.yumengse.cn
http://www.parniss.cn