react router 部署在Nginx 子目录下报错Uncaught SyntaxError: Unexpected token 加载不到static下的JS

背景介绍:

        解决react router 打包之后部署在Nginx子目录下,在子页面刷新时会报404的问题。

 

看错误截图

 

修改Nginx配置文件 nginx/conf.d/default.conf 文件,配置如下:

#lifecoach
	location  ~ /lifecoach{
		#禁用缓存
	 	#proxy_buffering off;
		root /data/ng_src_file;
		try_files $uri /lifecoach/index.html; # 在所有路由下刷新都重新指向index.html
   	}

开始使用配置如下,这个配置会报标题中的错误:


	location  ~ /lifecoach{
		#禁用缓存
	 	#proxy_buffering off;
		rewrite .* /lifecoach/index.html break; # 这个配置不行,会报标题中的错误
     	root /data/ng_src_file;
   	}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章