一、首先安装路由模块
npm i vue-router -S
注:如果安装过脚手架,那么在安装得时候就会提示安装此模块。
二、在主文件中引入路由
import VueRouter from "vue-router"
三、注明需要使用路由
Vue.use(VueRouter)
四、配置路由
const router = new VueRouter({
router: [ //固定得参数
{path:'/', //需要路由得地址,比如这里是根路径,也是跳转前得地址
component:Home},//跳转后的具体地址
{path:'/', //需要路由得地址,比如这里是根路径,也是跳转前得地址
component:Home},//跳转后的具体地址
],
mode: "history" //去除地址栏的#
})
五、使用路由专门的标签跳转
<router-link to="/" /*等价于a标签的href属性*/ ></router-link>