vue設置默認首頁的操作
更新時間:2020年08月12日 15:38:50 作者:weixin_43034862
這篇文章主要介紹了vue設置默認首頁的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
在router.js設置如下:
index就是默認頁面
const routes = [
// 公司項目
{ path: '/', redirect: '/index' },
{path:'/index',component:index},
{
path:'/example',
component:example,
redirect:'/edetail',
children:[
{path:'/edetail',component:edetail}
]
},
{path:'/login',component:login}
]
不使用在根目錄設置router的方法,跳轉(zhuǎn)頁面帶不同的頭部信息時容易出現(xiàn)問題
補充知識:vue-router默認的首頁渲染設置
當一個vue項目的頁面打開,總得有一個默認的首頁組件自動出現(xiàn)
不能只是點擊首頁的跳轉(zhuǎn)才出現(xiàn)
這個默認的打開路由配置需要在router.js中的 VueRouter 實例中,改變routes數(shù)組
const router = new VueRouter({
routes:[
{
path:'/',
//redirect 是重新定向
redirect:'/home'
},
{
path:'/home',
component:Home
}
]
})
這樣設置之后,就將默認的路由路徑設置為/home
以上這篇vue設置默認首頁的操作就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vue3使用Proxy實現(xiàn)數(shù)據(jù)監(jiān)聽的原因分析
在本篇文章里小編給大家整理的是一篇關(guān)于Vue3使用Proxy實現(xiàn)數(shù)據(jù)監(jiān)聽的原因分析內(nèi)容,有需要的朋友們可以跟著學習參考下。2021-11-11

