vue快速入门(五十一)历史模式

注释很详细,直接上代码

上一篇

新增内容
历史模式配置方法

默认哈希模式,历史模式与哈希模式在表层的区别是是否有/#/

其他差异暂不深究
源码

html 复制代码
//导入所需模块
import Vue from "vue";
import VueRouter from "vue-router";
import myMusic from "@/views/myMusic.vue";
import findMusic from "@/views/findMusic.vue";
import attentionSigner from "@/views/attentionSigner.vue";
import recommendList from "@/views/recommendList.vue";
import rankingList from "@/views/rankingList.vue";
import songList from "@/views/songList.vue";
//调用函数将VueRouter插件安装为Vue的插件
Vue.use(VueRouter);

//配置路由规则
const routes = [
  //重定向
  { path: "/", redirect: "/MyMusic/recommendList" },
  {
    path: "/myMusic",
    component: myMusic,
    // 二级路由无需写'/'
    children: [
      {
        path: "recommendList",
        component: recommendList,
      },
      {
        path: "rankingList",
        component: rankingList,
      },
      {
        path: "songList",
        component: songList,
      },
    ],
  },
  {
    // 动态路由接受参数(后面加问号表示为可选参数)
    path: "/findMusic/:name?",
    component: findMusic,
  },
  {
    path: "/attentionSigner",
    component: attentionSigner,
  },
];

//创建路由实例
const router = new VueRouter({
  // 路由配置
  routes,
  //历史模式
  mode: 'history'
  //这里可以修改router-link的默认类名
  /*
    linkActiveClass:'my-active-class',
    linkExactActiveClass:'my-exact-active-class'
    */
});
//导出路由实例
export default router;

效果演示

相关推荐
淡笑沐白14 小时前
ECharts入门指南:数据可视化实战
前端·javascript·echarts
魔卡少女114 小时前
Nginx配置代码化自动部署詹金斯/Github方案
前端·nginx·github
开发者如是说14 小时前
可能是最好用的多语言管理工具
android·前端·后端
是上好佳佳佳呀14 小时前
【前端(六)】HTML5 新特性笔记总结
前端·笔记·html5
北城笑笑14 小时前
FPGA 与 市场主流芯片分类详解:SoC/CPU/GPU/DPU 等芯片核心特性与工程应用
前端·单片机·fpga开发·fpga
A923A14 小时前
【从零开始学 React | 第四章】useEffect和自定义Hook
前端·react.js·fetch·useeffect
ZC跨境爬虫14 小时前
批量爬取小说章节并优化排版(附完整可运行脚本)
前端·爬虫·python·自动化
ZC跨境爬虫14 小时前
海南大学交友平台登录页开发实战day4(解决python传输并读取登录信息的问题)
开发语言·前端·python·flask·html
来一颗砂糖橘15 小时前
pnpm:现代前端开发的高效包管理器
前端·pnpm
前端摸鱼匠15 小时前
Vue 3 的defineProps编译器宏:详解<script setup>中defineProps的使用
前端·javascript·vue.js·前端框架·ecmascript