I am currently working with Laravel 5.3 and utilizing the built-in VueJs components.
At this point, my goal is to implement routes into my project. I have attempted to use the following code, but unfortunately, it is not functioning as expected.
const NotFound = { template: '<p>Page not found</p>' }
const Page1 = { template: '<p>home page</p>' }
const Page2 = { template: '<p>about page</p>' }
const routes = {
'/': Page1,
'/page2': Page2
}
const app = new Vue({
el: '#app',
data: {
currentRoute: window.location.pathname
},
computed: {
ViewComponent () {
return routes[this.currentRoute] || NotFound
}
},
render (h) { return h(this.ViewComponent) }
});
How can I import Example.vue
instead of using Page1
?
I attempted to use
require('./components/Example.vue')
, but it did not work as expected. Any guidance on how to resolve this issue would be greatly appreciated.