This is my component:
const Vue = require("vue/dist/vue.js");
const qs = require("querystring");
module.exports = Vue.component("Page",function(resolve){
console.log($route);
let id = this.$route.params.id;
fetch("/getPage.json",{
method:"POST",
body:qs.stringify({
id
})
}).then(r=>r.json())
.then(j=>{
console.log(j);
resolve({
template:`<h1>`+JSON.stringify(j)+"</h1>"
});
})
});
And this is my router:
const router = new VueRouter({
mode:"history",
routes:[
{
path:"/",
component:Home
},
{
path:"/me",
component:Me
},
{
path:"/create-page",
component:createPage
},
{
path:"/p/:id",
component:Page
}
]
});
Vue.use(VueRouter);
When i run this app i get:
ReferenceError: $route is not defined
I tried using this.$route
but it's not working. I'm using an arrow function. When i do this it works:
const Vue = require("vue/dist/vue.js");
module.exports = Vue.component("Page",function(resolve){
resolve({
template:`<h1>{{$route.params.id}}`
});
});
Please help me figure out how to fix this.