vue 在單頁面應(yīng)用里使用二級套嵌路由
在一個(gè)單頁面應(yīng)用里使用二級套嵌路由
目錄結(jié)構(gòu)如下:

其中main.js為全局配置文件,App.vue為項(xiàng)目入口。
main.js中路由配置如下
import Vue from 'vue'//引入vue
import App from './App'//引入主模板
import Router from 'vue-router'// 引入router路由
// 引入項(xiàng)目的模塊組件
import licai from './components/licai'
import home from './components/home'
import wode from './components/wode'
import home1 from './components/home/home1'
import home2 from './components/home/home2'
import home2_1 from './components/home/home2_box/home2_1'//套嵌路由
import home2_2 from './components/home/home2_box/home2_2'
Vue.use(Router)// 使用router
// 定義路由
var routes = [
{ path: '/', redirect: '/home' },//默認(rèn)顯示home
{
path: '/home',
component: home,//路徑home的組件是home
meta: { navShow: true}
}, {
path: '/licai',
component: licai,
meta: { navShow: true}
}, {
path: '/wode',
component:wode,
meta: { navShow: true}
},{
path:'/home1/:num',
component:home1,
meta: { navShow: false}
},{
path:'/home2',
component:home2,
meta: { navShow: false},
//這里定義了兩個(gè)子路由在home2模塊下
children:[
{ path: '/home2/home2_1', component:home2_1},
{ path: '/home2/home2_2', component:home2_2}
]
}]
// 實(shí)例化路由
var vueRouter = new Router({
routes//此路由為上方定義
})
// 創(chuàng)建和掛載根實(shí)例
new Vue({
el: '#app',//vue項(xiàng)目在哪個(gè)元素下
router: vueRouter,//使用路由
template: '<App></App>',
components: { App }
})
App.vue為主模板,也就是入口文件,其中定義的路由與一級路由無任何區(qū)別:
<template>
<div id="app1">
<div class="nav-bottom" v-show="$route.meta.navShow">
<!-- 引入公用的頭部 header組件 -->
<v-header></v-header>
</div>
<div class="contianer">
<!-- 路由中的組件在這里被渲染,默認(rèn)被渲染的為home組件,已在路由配置中設(shè)置 -->
<router-view></router-view>
</div>
</div>
</template>
home.vue,這里是首頁,從這里可以進(jìn)入home2頁面:
<template>
<div class="home box">
<h3>這里是home頁面</h3>
<router-link to="/home2">套嵌路由</router-link>
</div>
</template>
home2.vue,這里可以展示套嵌路由了:
<template id="home2">
<div>
<header class="home header"><a href="javascript:void(0);" rel="external nofollow" οnclick="javacript:window.history.go(-1)"><img src="../../../static/img/png1.png"/></a>路由套嵌</header>
<router-link to="/home2/home2_1">子頁面1</router-link>
<router-link to="/home2/home2_2">子頁面2</router-link>
<!-- 路由匹配到的組件將渲染在這里 -->
<router-view></router-view>
</div>
</template>
<style>
.home.header{font-size:0.8rem;position:relative;}
.home.header>a{display: block;height:0.8rem;width:0.4rem;margin-top:0.6rem;position:absolute;left:0.5rem;}
.home.header>a>img{height:100%;width:100%;display:block;}
</style>
效果:

以上就是vue 在單頁面應(yīng)用里使用二級套嵌路由的詳細(xì)內(nèi)容,更多關(guān)于vue 使用二級嵌套路由的資料請關(guān)注腳本之家其它相關(guān)文章!
- ant design vue導(dǎo)航菜單與路由配置操作
- 針對Vue路由history模式下Nginx后臺配置操作
- vue-router 控制路由權(quán)限的實(shí)現(xiàn)
- 解決vue-router 嵌套路由沒反應(yīng)的問題
- vue中路由跳轉(zhuǎn)不計(jì)入history的操作
- 在vue中實(shí)現(xiàn)某一些路由頁面隱藏導(dǎo)航欄的功能操作
- VUE : vue-cli中去掉路由中的井號#操作
- vue.js使用watch監(jiān)聽路由變化的方法
- VueJs路由跳轉(zhuǎn)——vue-router的使用詳解
- vue 解決addRoutes動態(tài)添加路由后刷新失效問題
- Vue+axios 實(shí)現(xiàn)http攔截及路由攔截實(shí)例
- vue使用require.context實(shí)現(xiàn)動態(tài)注冊路由
相關(guān)文章
Vue router傳遞參數(shù)并解決刷新頁面參數(shù)丟失問題
這篇文章主要介紹了Vue router傳遞參數(shù)并解決刷新頁面參數(shù)丟失問題,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12
Vue中使用vue-i18插件實(shí)現(xiàn)多語言切換功能
在基于vue-cli項(xiàng)目開發(fā)過程中,多語言切換功能可使用vue-i18插件,這篇文章分步驟給大家介紹了Vue中使用vue-i18插件實(shí)現(xiàn)多語言切換功能,感興趣的朋友一起看看吧2018-04-04
在 Linux/Unix 中不重啟 Vim 而重新加載 .vimrc 文件的流程
這篇文章主要介紹了在 Linux/Unix 中不重啟 Vim 而重新加載 .vimrc 文件的流程,需要的朋友可以參考下2018-03-03
vue 實(shí)現(xiàn)購物車總價(jià)計(jì)算
今天小編就為大家分享一篇vue 實(shí)現(xiàn)購物車總價(jià)計(jì)算,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-11-11
vue3.0 Reactive數(shù)據(jù)更新頁面沒有刷新的問題
這篇文章主要介紹了vue3.0 Reactive數(shù)據(jù)更新頁面沒有刷新的問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-04-04
vue項(xiàng)目使用可選鏈操作符編譯報(bào)錯(cuò)問題及解決
這篇文章主要介紹了vue項(xiàng)目使用可選鏈操作符編譯報(bào)錯(cuò)問題及解決方案,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03
vue2.0如何實(shí)現(xiàn)echarts餅圖(pie)效果展示
這篇文章主要介紹了vue2.0如何實(shí)現(xiàn)echarts餅圖(pie)效果展示,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-10-10
vue+Element實(shí)現(xiàn)搜索關(guān)鍵字高亮功能
這篇文章主要為大家詳細(xì)介紹了vue+Element實(shí)現(xiàn)搜索關(guān)鍵字高亮功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-05-05

