在router.js設置如下:
index就是默認頁面
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
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的方法,跳轉頁面帶不同的頭部信息時容易出現問題
補充知識:vue-router默認的首頁渲染設置
當一個vue項目的頁面打開,總得有一個默認的首頁組件自動出現
不能只是點擊首頁的跳轉才出現
這個默認的打開路由配置需要在router.js中的 VueRouter 實例中,改變routes數組
1
2
3
4
5
6
7
8
9
10
11
12
13
|
const router = new VueRouter({ routes:[ { path: '/' , //redirect 是重新定向 redirect: '/home' }, { path: '/home' , component:Home } ] }) |
這樣設置之后,就將默認的路由路徑設置為/home
以上這篇vue設置默認首頁的操作就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持服務器之家。
原文鏈接:https://blog.csdn.net/weixin_43034862/article/details/83379103