[Vuejs]-Cannot read properties of undefined (reading 'push') in vue js

0πŸ‘

At the point that you are calling this.$router, it is undefined

Make sure you have made the router globally available in your Vue app.

Make sure that this component can "see" your router. The easiest way to check is to add a mounted hook to the JoinRoom component:

mounted() {
  console.log({router: this.$router});
}

Report back what that displays.

I am assuming the JS code you showed is from JoinRoom.vue

Please confirm that it is inside the methods of the export default section of the JS code. Outside that, this will not mean what you want it to mean.

Your error message refers to JoinRoom.vue.

But you have shown us ChatRoom.vue.

Leave a comment