title: Redirect to login page when user is logout in Vue
body: <p>I am very beginner in JS and VUE.
  I make mini CMS in Vue and Laravel. I create this router in Vue:</p>
  <pre><code>import Vue from 'vue'
  import Router from 'vue-router'
  
  // Containers
  const TheContainer = () =&gt; import('@/containers/TheContainer')
  
  // Views
  const Dashboard = () =&gt; import('@/views/Dashboard')
  ....
  
  Vue.use(Router)
  
  let router = new Router({
    mode: 'hash', // https://router.vuejs.org/api/#mode
    linkActiveClass: 'active',
    scrollBehavior: () =&gt; ({ y: 0 }),
    routes: configRoutes()
  })
  
  
  router.beforeEach((to, from, next) =&gt; {
    let roles = localStorage.getItem(&quot;roles&quot;);
  
    if(roles != null){
      roles = roles.split(',')
    }
    if(to.matched.some(record =&gt; record.meta.requiresAdmin)) {
      if(roles != null &amp;&amp; roles.indexOf('admin') &gt;= 0 ){
        next()
      }else{
        next({
          path: '/login',
          params: { nextUrl: to.fullPath }
        })
      }
    }else if(to.matched.some(record =&gt; record.meta.requiresUser)) {
      if(roles != null &amp;&amp; roles.indexOf('user') &gt;= 0 ){
        next()
      }else{
        next({
          path: '/login',
          params: { nextUrl: to.fullPath }
        })
      }
    }else{
      next()
    }
  })
  
  export default router
  
  function configRoutes () { 
    return [
      {
        path: '/',
        redirect: '/dashboard',
        name: 'Home',
        component: TheContainer,
        children: [
          {
            path: 'dashboard',
            name: 'Dashboard',
            component: Dashboard
          },
            ]
          },
    ]
  }
  </code></pre>
  <p>It's work fine, but I have 2 problems:</p>
  <ol>
  <li>When user is not login - then I need redirect to my login page (/login) - not to /dashboard</li>
  <li>When user session was expired - then redirect to login page</li>
  </ol>
  <p>If user is login - then first page (and main page) is /dashboard</p>
  <p>How can I make it?</p>
  <p>Please help me.</p>