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 }
];
相关推荐
kyriewen5 分钟前
我用了三周Claude Code Skills——总结出5条铁律,第3条最反直觉
前端·ai编程·claude
阳光是sunny9 分钟前
LangGraph实战教程:控制流详解
前端·人工智能·后端
格尔曼Noah1 小时前
Safari浏览器中如何只允许指定网站下载
前端·safari
用户059540174462 小时前
用了3年Redis,才发现我一直没搞懂缓存一致性测试
前端·css
swipe2 小时前
07|(前端转后全栈)为什么后端也要缓存?从前端缓存思维理解 Redis
前端·后端·全栈
IT小盘2 小时前
05-企业项目统一接入多个大模型-适配器模式实战
前端·人工智能·适配器模式
swipe2 小时前
06|(前端转后全栈)登录后端到底在做什么?JWT、Spring Security 和权限链路
前端·后端·全栈
海上彼尚3 小时前
Nodejs也能写Agent - 22.LangGraph篇 - 上下文工程
前端·javascript·人工智能·langchain·node.js
阳光是sunny3 小时前
LangGraph实战教程:预定义状态MessagesState与AgentState
前端·人工智能·后端