title: Redirect to requested page after login using vue-router
body: <p>In my application some routes are just accessible for authenticated users.<br>When a unauthenticated user clicks on a link, for which he has to be signed in, he will be redirected to the login component.<br><br>
  If the user logs in successfully, <strong>I would like to redirect him to the URL he requested before he had to log in</strong>. However, <strong>there also should be a default route</strong>, in case the user did not request another URL before he logged in.<br><br>
  <strong>How can I achieve this using vue-router?</strong><br><hr>
  <strong>My code without redirect after login</strong></p>
  <pre class="lang-js prettyprint-override"><code>router.beforeEach(
      (to, from, next) =&gt; {
          if(to.matched.some(record =&gt; record.meta.forVisitors)) {
              next()
          } else if(to.matched.some(record =&gt; record.meta.forAuth)) {
              if(!Vue.auth.isAuthenticated()) {
                  next({
                      path: '/login'
                      // Redirect to original path if specified
                  })
              } else {
                  next()
              }
          } else {
              next()
          }
      }        
  )
  </code></pre>
  <p><br><br>
  <strong>My login function in my login component</strong></p>
  <pre class="lang-js prettyprint-override"><code>login() {
      var data = {
          client_id: 2,
          client_secret: '**************',
          grant_type: 'password',
          username: this.email,
          password: this.password
      }
      // send data
      this.$http.post('oauth/token', data)
           .then(response =&gt; {
               // authenticate the user
               this.$auth.setToken(response.body.access_token,
               response.body.expires_in + Date.now())
               // redirect to route after successful login
               this.$router.push('/')
            })
  }
  </code></pre>