Home  >  Article  >  Web Front-end  >  Introduction to the configuration method of router in vue.js

Introduction to the configuration method of router in vue.js

不言
不言Original
2018-08-23 16:09:062405browse

This article brings you an introduction to the configuration method of routers in vue.js. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Install the routing module in the vue project

npm install vue-router --save-dev

Before configuring routing, let’s first understand the b988a8fd72e5e0e42afffd18f951b277 and 975b587bf85a482ea10b0a28848e78a4 tags
a18f1fb9a1944f223457f05172f100a5 and 3499910bf9dac5ae3c52d5ede7383485 tags have the same function and are used for jumping

<router-link to="/body">点我跳转页面</router-link>

to. Inside is the address. Ignore it for now, because "/body" is defined when configuring routing

975b587bf85a482ea10b0a28848e78a4 Function: When you click b988a8fd72e5e0e42afffd18f951b277, the page you need to jump to is displayed in it, a bit like the 04a0d55efbbfd646a993fbc01f262c57

<div>
   <router-view></router-view>
</div>

Configuring Router## in H5

#Introduce and configure the router module in the main.js file

//main.js

//引进路由器模块
import VueRouter from &#39;vue-router&#39;

//引进跳转的 组件页面地址
import App_head from &#39;./App_head&#39;
import body_z from &#39;./components/HelloWorld&#39;

Vue.config.productionTip = false;
Vue.use(VueRouter);

//配置路由器
const router = new VueRouter({
  routes:[
    //path为 "/" 意思是:<router-view> 标签初始显示的地址
    //component为上面 组件名
    {path:"/",component:App_head},              
    {path:"/body",component:body_z}
  ],
  mode:"history"                 //定义这个后,打开网页,8080后面不会跟着 /#/ 的符号
});

new Vue({
  router,                              //记得在这里定义路由器,否则不能使用
  el: &#39;#app_body&#39;,
  components: { App_body },
  template: &#39;<App_body/>&#39;
})
After the router is defined, use it with the b988a8fd72e5e0e42afffd18f951b277 and 975b587bf85a482ea10b0a28848e78a4 tags


<div>
   //点击后,跳转到http://localhost:8080/body  
   //点击后,<router-view>将显示 HelloWorld 组件的内容
   <router-link to="/body">跳转页面</router-link>       
   <router-view></router-view>
</div>

Related recommendations:

Nested routing (sub-routing) of Vue.js

Vue. js route naming and named views

The above is the detailed content of Introduction to the configuration method of router in vue.js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn