Home > Article > Web Front-end > Detailed explanation of vue-router single page routing
This article mainly introduces the relevant information of vue-router single page routing in detail. It has certain reference value. Interested friends can refer to it
vue Among them, there is a class library called vue-router, which is used for single-page routing. Routing is generally divided into four steps:
Prepare a root component vue.extend();
Prepare template for the content that needs to be routed ;
Prepare routing new VueRouter();
Associated routing map
Start routing start (App,'#box'); //The first parameter is the prepared root component, and the second parameter is the location to be bundled in the id defined by yourself
https://github.com/vuejs/vue-router
The simple code for routing jump is as follows:<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script type="text/javascript" src="js/vue.js" ></script> <script type="text/javascript" src="js/vue-router.js" ></script> <script type="text/javascript" src="js/vue-resource.js" ></script> <title></title> </head> <body> <p id="box"> <ul> <li> <a v-link="{path:'/home'}">我是第一个a</a> </li> <li > <a v-link="{path:'news'}">我是第二个a</a> </li> </ul> <p> <router-view></router-view> </p> </p> </body> <script> //1.准备一个根组件 var App=Vue.extend(); //2.Home News 组件准备 var Home=Vue.extend({ template:'<h3>我是第一个a的内容页</h3>' }); var News=Vue.extend({ template:'<h3>我是第二个a的内容页</h3>' }) //3.准备路由 var router = new VueRouter(); //4.关联 router.map({ 'home':{ component:Home }, 'news':{ component:News } }) //5.启动路由 router.start(App,'#box'); </script> </html>
The above is the detailed content of Detailed explanation of vue-router single page routing. For more information, please follow other related articles on the PHP Chinese website!