refer: https://v3.router.vuejs.org/installation.html#direct-download-cdn

1.安装依赖:

npm install vue-router

2.创建router.js,使用vue-router

import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

例如:

<span style="color:#dcc6e0">import</span> Vue <span style="color:#dcc6e0">from</span> <span style="color:#abe338">&#39;vue&#39;</span>;
<span style="color:#dcc6e0">import</span> VueRouter <span style="color:#dcc6e0">from</span> <span style="color:#abe338">&#39;vue-router&#39;</span>;
<span style="color:#dcc6e0">import</span> HelloWorld <span style="color:#dcc6e0">from</span> <span style="color:#abe338">&#39;./components/HelloWorld.vue&#39;</span>;
Vue.use(VueRouter);
export <span style="color:#dcc6e0">default</span> <span style="color:#f5ab35">new</span> Router({
routes: [
{
<span style="color:#f5ab35">path</span>: <span style="color:#abe338">&#39;/hello_world&#39;</span>,
<span style="color:#f5ab35">name</span>: <span style="color:#abe338">&#39;HelloWorld&#39;</span>,
component: HelloWorld
},
]
});

此时,打开http://localhost:8081/hello_world就可以看到页面了: