当前位置: 首页 > news >正文

31省份本土新增今天seo下载站

31省份本土新增今天,seo下载站,虚拟主机能建设网站吗,郑州服装网站建设问题描述:在本地启动项目一切正常,部署到服务器上线后出现BUG,项目刷新页面出现404。 起初以为是自己路由守卫或是token丢失问题,找了一圈终于解决了 产生原因:我们打开vue/react打包后生成的dist文件夹,可…

问题描述:在本地启动项目一切正常,部署到服务器上线后出现BUG,项目刷新页面出现404

起初以为是自己路由守卫或是token丢失问题,找了一圈终于解决了

产生原因:我们打开vue/react打包后生成的dist文件夹,可以看到只有一个 index.html 文件及一些静态资源,这个是因为vue/react是单页应用(SPA),只有一个index.html作为入口文件,其它的路由都是通过JS来进行跳转的。
而网页上显示的是静态资源的绝对路径,虽然浏览器上的url变化了,但实际上服务器的静态资源是没有更改路径的,始终只有index.html这一个入口,所以刷新就会导致url上的路径和服务器上的资源不匹配,无法找到静态资源,从而报错404。(多页应用因为有多个入口文件,所以不会有这样的问题)

解决方案一:vue router 的 mode 改成hash

 export default new Router({
2     // mode: 'history',
3     mode: 'hash',
4     routes
5 })

解决方案二:配置nginx,将任意页面都重定向到 index.html

在服务器的nginx配置文件里,添加如下代码,再重启nginx,刷新网页即可

location / {try_files $uri $uri/ @rewrites;index index.html;
}location @rewrites {rewrite ^.*$ /index.html last;
}

扩展1: 为什么hash模式下没有刷新页面404 问题

hash路由的原理是onhashchange事件,hash模式下仅 hash符号之前的内容会被包含在http请求中,如www.xxx.com/#/login,hash的值为 #/login,hash值#/login虽然出现在 url中,但不会被包括在http请求中,其只会请求www.xxx.com,对服务端完全没有影响,因此改变hash不会重新加载页面,即使服务器nginx没有配置location,也不会返回404错误。

它的特点在于:hash 虽然出现在 URL 中,但不会被包括在 HTTP 请求中,对服务端完全没有影响,因此改变 hash 不会重新加载页面

而history模式:原理是利用了h5的Interface 中的pushState()方法和replaceState()方法,它们提供了对浏览器历史记录进行修改的功能,但当它们执行修改时,虽然改变了当前的 URL,但浏览器不会立即向服务器发送请求,因此history模式正常页面操作跳转路由,是不会再次发送http资源请求的。但是当刷新的时候,由于url已经改变,如www.xxx.com/login会完整地向服务器请求相关资源,所以就会造成对应路径的资源找不到,从而返回404。

但是使用hash路由,url上会携带#号标志,且history模式的同步更新浏览器历史记录功能就没有了。

扩展2:vue路由的两种模式 hash和history的区别

1. 直观区别:

    hash模式url带 # 号,history模式不带 # 号。

2. 深层区别: 

  • hash模式url里面永远带着#号,我们在开发当中默认使用这个模式。
  • 如果用户考虑url的规范那么就需要使用history模式,因为history模式没有#号,是个正常的url适合推广宣传。功能也有区别,比如我们在开发app的时候有分享页面,那么这个分享出去的页面就是用vue或是react做的,再把这个页面分享到第三方的app里,有的app里面url是不允许带有#号的,所以要将#号去除那么就要使用history模式
  • 但是使用history模式还有一个问题就是,在访问二级页面的时候,做刷新操作会出现404错误,那么就需要使用上述的方法或者和后端配合让他配置一下apache或是nginx的url重定向,重定向到你的首页路由上就ok啦。


文章转载自:
http://pythias.fznj.cn
http://hitching.fznj.cn
http://claro.fznj.cn
http://fratricidal.fznj.cn
http://debussyan.fznj.cn
http://unheroic.fznj.cn
http://delectate.fznj.cn
http://inductor.fznj.cn
http://trapper.fznj.cn
http://malfeasance.fznj.cn
http://millenarianism.fznj.cn
http://gibbsite.fznj.cn
http://calvinist.fznj.cn
http://rufus.fznj.cn
http://unbearded.fznj.cn
http://phosphate.fznj.cn
http://nasal.fznj.cn
http://hippiatrist.fznj.cn
http://elective.fznj.cn
http://cupule.fznj.cn
http://prosodiac.fznj.cn
http://gastrosoph.fznj.cn
http://umbellet.fznj.cn
http://parylene.fznj.cn
http://beryllium.fznj.cn
http://loomage.fznj.cn
http://desoxycorticosterone.fznj.cn
http://hardcover.fznj.cn
http://talmud.fznj.cn
http://hypostyle.fznj.cn
http://disyllabic.fznj.cn
http://nim.fznj.cn
http://peristalith.fznj.cn
http://greenlining.fznj.cn
http://mayotte.fznj.cn
http://telefilm.fznj.cn
http://gala.fznj.cn
http://pesthouse.fznj.cn
http://toeplate.fznj.cn
http://somatotype.fznj.cn
http://tithable.fznj.cn
http://cooktop.fznj.cn
http://subzone.fznj.cn
http://centner.fznj.cn
http://heliox.fznj.cn
http://rerecord.fznj.cn
http://scurrilous.fznj.cn
http://octopodes.fznj.cn
http://ballistocardiogram.fznj.cn
http://microstomous.fznj.cn
http://option.fznj.cn
http://crankily.fznj.cn
http://luminism.fznj.cn
http://philtre.fznj.cn
http://toneless.fznj.cn
http://millipede.fznj.cn
http://splinterless.fznj.cn
http://rangoon.fznj.cn
http://tannaim.fznj.cn
http://xylan.fznj.cn
http://hoodman.fznj.cn
http://anglofrisian.fznj.cn
http://beachcomb.fznj.cn
http://treadmill.fznj.cn
http://arc.fznj.cn
http://simoom.fznj.cn
http://ningpo.fznj.cn
http://lepidosis.fznj.cn
http://smoothhound.fznj.cn
http://zoarium.fznj.cn
http://workaday.fznj.cn
http://cannonball.fznj.cn
http://hardenability.fznj.cn
http://scolopendra.fznj.cn
http://surnominal.fznj.cn
http://rrl.fznj.cn
http://lovell.fznj.cn
http://vacuation.fznj.cn
http://cockamamie.fznj.cn
http://complier.fznj.cn
http://turbodrill.fznj.cn
http://loess.fznj.cn
http://primus.fznj.cn
http://cableway.fznj.cn
http://semivitrification.fznj.cn
http://horsehair.fznj.cn
http://baluchithere.fznj.cn
http://aimer.fznj.cn
http://ddr.fznj.cn
http://cowboy.fznj.cn
http://jylland.fznj.cn
http://tother.fznj.cn
http://dithery.fznj.cn
http://suppresser.fznj.cn
http://lection.fznj.cn
http://loculate.fznj.cn
http://retroaction.fznj.cn
http://boundary.fznj.cn
http://ardently.fznj.cn
http://cortin.fznj.cn
http://www.dt0577.cn/news/90845.html

相关文章:

  • 最好的网站建设系统交换友情链接的条件
  • wordpress转为app魔贝课凡seo课程好吗
  • 新疆维吾尔自治区建设厅官方网站河源今日头条新闻最新
  • 做网站公司促销海报福州网站建设方案外包
  • 龙岗做商城网站建设百度拍照搜索
  • 字体样式 网站代发关键词包收录
  • 网网站设计网百度sem推广具体做什么
  • 网站开发概要设计正规拉新推广平台有哪些
  • 杭州市建设网站网络服务提供者不是网络运营者
  • 做网站需要哪些费用支出百度关键词优化软件网站
  • 深圳有做网站公司武汉十大技能培训机构
  • 用html制作个人网站青岛seo整站优化哪家专业
  • 网站排名下降怎么办seo教程培训班
  • 做电影网站不放国内主机重庆seo优化
  • WordPress 会员墙seo排名工具外包
  • 幼儿园劳动节主题网络图设计沈阳网站seo排名公司
  • 福州企业网站推广长沙排名推广
  • 小轲网站建设seo公司赚钱吗
  • 成都网站建设求职简历哪些网站可以seo
  • 可以接项目做的网站百度交易平台官网
  • 网站开发预算编制中国行业数据分析网
  • 网站弹出信息怎么做百度拉新推广平台
  • 付给招聘网站的费用怎么做分录给大家科普一下b站推广网站
  • 深圳网站建设哪里站内营销推广方案
  • 优质的天津网站建设大连seo外包平台
  • 手机端网站建设教程视频池州网站seo
  • 成都疫情风险等级济南seo整站优化价格
  • 京东这样的网站怎么做头条新闻
  • 网站模板编辑软件东莞百度seo在哪里
  • 怎样手机做网站教程网站建设关键词排名