question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot access to this.$router in custom method

See original GitHub issue

Hi, i would like to access to this.$router.push('/home') in a custom method, i get this error Cannot read property 'push' of undefined

import Vue from 'vue'
import Component from 'vue-class-component'
import AuthService from "../../../../main/services/api/auth/auth.service";

@Component
export default class Login extends Vue {

    login: string = "";
    password: string = "";

    /**
     * Classes
     */
    authService = this.$container.get<AuthService>(AuthService.name);

    submit() {
        console.log('login: ' + this.login);
        console.log('password: ' + this.password);
        this.authService.login(this.login, this.password).then((res) => {
            console.log(this);
            this.$router.push('/home');
        });
        return false;
    }

    mounted() {
        console.log(this);
    }
}


<template>
    <div>
        <form v-on:submit.prevent="submit()">
            <input name="login" v-model="login"/><br>
            <input name="password" type="password" v-model="password"/>
            <button type="submit"></button>
        </form>

    </div>
</template>

<script lang="ts">
   import Login from './Login'
   export default Login
</script>

<style scoped>

</style>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
leohubertcommented, Sep 3, 2019

Hi @Worie, i never found a solution unfortunately…

1reaction
ktsncommented, Jul 3, 2018

Closing as reproduction is not provided in a long time. Please open a new issue with a self-contained reproduction when you can follow up information.

Read more comments on GitHub >

github_iconTop Results From Across the Web

vue-router can't access my component - Stack Overflow
The thing I need to say is, that I am adding a new route after a userinput and then I can't access to...
Read more >
How To Navigate Between Views with Vue Router
In your text editor, open the AirportDetail.vue component. To achieve this, detect if airport.value is undefined. This function will be called ...
Read more >
Complete Vue Router 4 Guide: Basics, Programmatic Routing ...
The createRouter method is what we use to create a new Vue Router instance. ... We cannot just directly open our file in...
Read more >
Angular Router: Child Routes, Auxiliary Routes, Master Detail
Learn how to use the Angular Router, avoid common pitfalls, learn Child Routes, Auxiliary Routes, setup a Master Detail Routing Scenario.
Read more >
Testing Vue Router
The best way to illustrate how to test an app using Vue Router is to let the warnings guide us. The following minimal...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found