title: How to use router push inside a VueJs component?
body: <p>I have a navbar component, I need to redirect to the login component inside a logout method declared at navbar.</p>
  <p>I tried: <code>this.$router.push({name:'MyLogin'});</code></p>
  <p>But I see the error:</p>
  <blockquote>
  <p>vue-router.esm.js?8c4f:1897 TypeError: Cannot read property '$router' of undefined<br />
  at eval (main.js?56d7:68)</p>
  </blockquote>
  <p>How can I use router push inside a component?</p>
  <p>Or how can I inside this component make access to the router.</p>
  <p><strong>EDIT :</strong></p>
  <p>At the file: <strong>/src/router.js</strong> I have the Login route:</p>
  <pre><code>export default new Router({
      mode: 'history',
      routes: [
      {
          path: '/login',
          name: 'Login',
          component: LoginView
      },
  </code></pre>
  <p>And at the file: <strong>/src/components/Navibar.vue</strong> I have the doLogout method:</p>
  <pre><code>methods: {
      doLogout(){ 
      this.$router.push({name:'Login'}); 
  }
  </code></pre>
  <p>Being new to Vue js I tried this:</p>
  <pre><code>doLogout(){
     const router = new router({
      routes: [
                { 
                  path: '/login', 
                  name: 'Login', 
                  component: LoginView 
                }               
          ]
    })
   this.$router.push({name:'Login'}); 
  </code></pre>
  <p>}</p>
  <p>I see the error message:</p>
  <blockquote>
  <p>doLogout catch ReferenceError: LoginView is not defined at eval (VM2993 NaviBar.vue:324)</p>
  </blockquote>
  <p>So I tried to add the component:</p>
  <pre><code>Vue.component('LoginView', require('Login.vue'));
  </code></pre>
  <p>Which gives me the error:</p>
  <blockquote>
  <p>Module not found: Error: Can't resolve 'Login.vue'</p>
  </blockquote>
  <p>Maybe I am doing the wrong steps?</p>
  <p>Which is the correct way to enable <code>this.$router.push()</code> inside one component redirecting to another component?</p>