vue-router的两种模式实现原理
1.hash模式的简单实现
- 使用锚点跳转+监听hashChange事件
2.history模式的简单实现
- 因为使用history.pushState不会刷新页面,故使用history.pushState+监听pushState事件
- 关于history模式刷新页面404的问题,因为刷新页面之后相当于在改变之后的url去请求静态资源,而这个url在静态资源服务器中是没有的;
所以解决办法就是告诉服务器,当访问url不存在时,指向静态资源的index.html
location / {
try_files $uri $uri/ /index.html;
}