标签:save r.js home 并且 install rect direct use 挂载
3.1 导入vue-router并注册上
```
import VueRouter from 'vue-router';
Vue.use(VueRouter);
```
3.2 创建组件,并导入组件
```
import homePage from './components/home-page.vue';
import newsPage from './components/news-page.vue';
```
3.3 配置路由,定义路由->实例化路由->挂载路由
```
const routes = [
{ path: '/home', component: homePage },
{ path: '/news', component: newsPage },
{ path: '*', redirect: '/home' } /*默认跳转路由*/
]
const router = new VueRouter({
routes // (缩写)相当于 routes: routes
})
new Vue({
el: '#app',
router,
render: h => h(App)
})
```
使用路由,在根组件App.vue的模板里
<router-link to="/home">首页</router-link>
<router-link to="/news">新闻</router-link>
<hr>
<router-view></router-view>
标签:save r.js home 并且 install rect direct use 挂载
原文地址:https://www.cnblogs.com/lobin/p/9903984.html