首頁  >  文章  >  web前端  >  判斷頁面是否登陸

判斷頁面是否登陸

php中世界最好的语言
php中世界最好的语言原創
2018-04-16 16:58:591689瀏覽

這次帶給大家判斷頁面是否登陸,判斷頁面是否登陸的注意事項有哪些,以下就是實戰案例,一起來看一下。

如下:

router.beforeEach((to, from, next) => {
 if (to.matched.some(record => record.meta.requireAuth)){ // 判断该路由是否需要登录权限
 if (token) { // 判断当前的token是否存在
  next();
 }
 else {
  next({
  path: '/login',
  query: {redirect: to.fullPath} // 将跳转的路由path作为参数,登录成功后跳转到该路由
  })
 }
 }
 else {
 next();
 }
});

在這之前是給路由加一個meta屬性

{
 path: '/index',
 meta: {
  title: '',
  requireAuth: true, // 添加该字段,表示进入这个路由是需要登录的
 },
}

注意:但是事實是登入的時候大多時候不進行跳轉,所以這裡需要在login跳轉的路徑中再加一段:

if(this.$route.query.redirect){
//  let redirect = decodeURIComponent(this.$route.query.redirect);
  let redirect = this.$route.query.redirect;
  this.$router.push(redirect);
}else{
  this.$router.push('/');
 }

相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!

推薦閱讀:

table固定表頭讓表單橫向捲動

#Bootstrap下拉外掛dropdown使用技巧

#

以上是判斷頁面是否登陸的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn