Webpack打包文件之后不能访问

#1

路由使用的是browserRouter

打包前:
在devServer能正常访问,url: http://localhost:9104/list
"/list"为路由地址

打包后:
将打包文件放在nginx服务器上,通过80端口能够请求到html及main.js,但是无论怎么拼接路由,都访问不了
url:http://localhost/index.html ; 这个地址能够请求到打包出的index.html,及main.js
url:http://localhost/index.html/list ;504 gateway time-out (nginx 提示)
url:http://localhost/index.html#list ;空白

路由配置:

...
import { Switch, BrowserRouter as Router, Route, Link } from "react-router-dom";
...
render(
	    <Provider store={store}》
    		<Router 》
    			<div》
    				<Route path="/abc" component={Test}/》
    				<Route path="/list" component={List}/》
    			</div》
    		</Router》
    	</Provider》,
	document.getElementById("root")
);

求助~~~
请问webpack.conf.js需要配置还是Router设置或者其他地方可能有问题,求大神指导

#2

打包前和打包后有区别。个人感觉是不是在dependencies里面没有react-router-dom这个依赖,毕竟生产环境和开发环境还是有点不一样的吧。

#3

线上访问一下 http://localhost/list, 如果没问题,你就懂是怎么一回事了。

1 Like
#4

这个依赖是装了的,因为使用dev-server,是可以正常访问页面内容的。
已经解决了,还是非常感谢~:slight_smile:

#5

最后确实是要用你说的这个地址访问的:slight_smile:http://localhost/list

但是我是通过网上找的ng的配置,加了这段配置才可以访问
location /list {
if (!-e $request_filename){
rewrite ^(.*)$ /index.html break;
}
}

虽然解决了问题,但是不太明白为什么