routing
##Directory
Official route
For most single-page applications, it is recommended to use the officially supportedvue- router library
. More details can be found in vue-router documentation.
Simple routing from scratch
If you just need very For simple routing without introducing a full-featured routing library, you can dynamically render a page-level component like this:const NotFound = { template: '<p>Page not found</p>' } const Home = { template: '<p>home page</p>' } const About = { template: '<p>about page</p>' } const routes = { '/': Home, '/about': About } new Vue({ el: '#app', data: { currentRoute: window.location.pathname }, computed: { ViewComponent () { return routes[this.currentRoute] || NotFound } }, render (h) { return h(this.ViewComponent) } })
Combined with the HTML5 History API, you can create a small but complete customer end router. You can directly see Example Application
Integrate third-party routing
If you have a preferred third-party routing, Such asPage.js
or Director, the integration is as simple as . Here's a complete example using Page.js.