Vue2 VueRouter 路由配置(并设置为history模式,去除#)

src目录下创建router.js

import Vue from "vue";
import VueRouter from "vue-router";
import ExaminationList from "@/components/examination/ExaminationList";
import Home from "@/components/Home";


// 要告诉 vue 使用 vueRouter
Vue.use(VueRouter);

const routes = [
    {
    path: '/',
    component: Home
    },
    {
        path: '/list',
        component: ExaminationList
    }

]

var router =  new VueRouter({
    mode: 'history',//改为history模式,去除url里的#
    routes
})
export default router;

App.vue

<template>
  <div id="app">
    <router-view ></router-view>
  </div>
</template>

<script>

export default {
  name: 'App',
  components: {
  },
  data:()=>{
    return {

    }
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

main.js

引入router

import Vue from 'vue'
import App from './App.vue'
Vue.config.productionTip = false


import router from "@/router";
new Vue({
  router,
  render: h => h(App)
}).$mount('#app')

posted @ 2021-06-14 12:22  HumorChen99  阅读(41)  评论(0编辑  收藏  举报  来源