router.jscss
import Vue from 'vue'; //配置路由 import VueRouter from 'vue-router'; Vue.use(VueRouter); //1.建立組件 import Home from '../components/Home.vue'; import News from '../components/News.vue'; import User from '../components/User.vue'; //2.配置路由 注意:名字 const routes = [ { path: '/home', component: Home }, { path: '/news', component: News, name: 'news' }, { path: '/user', component: User }, { path: '*', redirect: '/home' } /*默認跳轉路由*/ ] //3.實例化VueRouter 注意:名字 const router = new VueRouter({ mode: 'history', /*hash模式改成history*/ routes // (縮寫)至關於 routes: routes }) //5 <router-view></router-view> 放在 App.vue export default router;
import Vue from 'vue';
import App from './App.vue';
//引入公共的scss 注意:建立項目的時候必須用scss
import './assets/css/basic.scss';
import router from './router/router.js';
//四、掛載路由
new Vue({
el: '#app',
router,
render: h => h(App)
})