Vue路由器的工作模式
1.history模式
优点:URL更加美观,不带有#,更接近传统的网站URL。
缺点:后期项目上线,需要服务端配合处理路径问题,否则刷新会有404错误。
const router = createRouter({ history: createWebHistory() // history模式 })
2. hash模式
优点:兼容性更好,因为不需要服务器端处理路径。
缺点:URL带有#,且在SEO优化方面相对较差。
const router = createRouter({ history: createWebHashHistory() // hash模式 })