Home  >  Article  >  Web Front-end  >  Determine whether the page is logged in

Determine whether the page is logged in

php中世界最好的语言
php中世界最好的语言Original
2018-04-16 16:58:591689browse

This time I will bring you the precautions to determine whether the page is logged in and whether the page is logged in. The following is a practical case, let's take a look.

is as follows:

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();
 }
});
Before that, add a meta

attribute to the route:

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

Note: But the fact is that most of the time there is no jump when logging in, so you need to add a section to the login jump path:

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('/');
 }
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

Fixed table header makes the form scroll horizontally

Bootstrap drop-down plug-in dropdown usage tips

The above is the detailed content of Determine whether the page is logged in. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn