Vue Router 的 history 模式与 hash 模式区别?路由懒加载怎么做?
- hash 模式:URL 带
#,如/foo#/bar,改动不刷新、不请求服务器,兼容好、无需服务端配置 - history 模式:URL 干净(
/foo/bar),但刷新/直接访问会 404,需服务端把所有路径 fallback 到index.html
const routes = [
{ path: '/about', component: () => import('./About.vue') } // 懒加载
]路由懒加载用动态 import(),配合 Webpack/Vite 自动拆分成独立 chunk,首屏只加载当前路由代码,大幅减小主包。