使用github actions檢測網站是否線上
阿新 • • 發佈:2020-11-16
vue使用redired對路由重定向:
{ path:'*', redirect:{ name:'login' } } 設定根目錄 { path:"/", name:'login', component:login, } 設定位址列地址正常顯示:新增mode:'history', 設定頁面是否登入,登入後正常跳轉,未登入跳轉至指定頁(登入頁) 在需要過濾的頁面新增mate>auth,不需要過濾頁面不用新增。 exportdefaultnewRouter({ mode:'history', routes:[{ path:"/", name:'login', component:login, },{ path:'/HelloWorld', name:'HelloWorld', component:HelloWorld, meta:{ auth:true }] }) 在main.js中新增router.beforeach守衛router.beforeEach((to, from, next) => { if (to.matched.some(m => m.meta.auth)) { // 對路由進行驗證 var token=sessionStorage.getItem("token"); if (token) { // 已經登陸 next() // 正常跳轉到你設定好的頁面 } else { // 未登入則跳轉到登陸介面,query:{ Rurl: to.fullPath}表示把當前路由資訊傳遞過去方便登入後跳轉回來; next({ name: 'login', query: { Rurl: to.fullPath } }) } } else { next() } })