Hey there! I'm trying to achieve a certain functionality where I want to redirect to a different page once a specific sequence is typed. Although I can see the message "It works" in my console, the redirection is not happening and instead, I am getting an error which says:
"Uncaught TypeError: Cannot read properties of undefined (reading '$router')"
Below is the code snippet I am using:
<script>
export default {
head() {
return {
script: [
{
src: "js/mousetrap.min.js",
},
],
};
},
components: {},
name: "IndexPage",
mounted() {
Mousetrap.bind("1 2", function () {
console.log("It works");
this.$router.push("/pagename");
return;
});
},
};
</script>
Just a heads up, I am making use of the Mousetrap library from .
Any suggestions on how to resolve this issue would be highly appreciated!