VueRouter 实例

分析下列代码

javascript 复制代码
const router = new VueRouter({
    mode:'history',
    routes
})
复制代码
1.const router = new VueRouter({ ... })
 用来创建一个 Vue Router 实例,用于管理 Vue.js 应用的路由。

2.mode: 'history':
作用: 启用 HTML5 History 模式,去除 URL 中的 # 符号(默认是 Hash 模式,如 http://example.com/#/home)。
效果: URL 更简洁(如 http://example.com/home)。
**注意:**需服务器配置(如 Nginx、Apache)支持,确保直接访问子路径时返回 index.html,否则会出现 404 错误。

3.routes:

作用:定义路由规则数组,每个路由映射到对应的 Vue 组件。

javascript 复制代码
const routes = [
  { path: '/', component: Home },
  { path: '/about', component: About }
];
相关推荐
2601_958492553 小时前
Optimizing Engagement with Freehead Skate - HTML5 Game - Construct 3
前端·html·html5
茉莉玫瑰花茶4 小时前
工作流的常见模式 [ 1 ]
java·服务器·前端
zhangxingchao5 小时前
AI应用开发六:企业知识库
前端·人工智能·后端
山峰哥5 小时前
SQL慢查询调优实战:从全表扫描到索引覆盖的完整复盘
前端·数据库·sql·性能优化
红尘散仙5 小时前
一个 `#[uniffi::export]`,把 Rust 接进 React Native
前端·后端·rust
moshuying5 小时前
AI Coding 最大的 token 黑洞,可能根本不是 prompt
前端
红尘散仙5 小时前
一行 `#[specta::specta]`,让 Tauri IPC 有类型
前端·后端·rust
lichenyang4536 小时前
HarmonyOS HMRouter 接入记录:从普通 Tab Demo 到路由跳转
前端
木斯佳6 小时前
前端八股文面经大全:腾讯WXG暑期前端一面(2026-05-15)·面经深度解析
前端·面试·笔试