如果带有参数的react-router的直接URL传递到浏览器会出错

Ahm*_*Ali 5 javascript reactjs react-router

文件 https://github.com/microcyberz/expensify

当我使用http://localhost:8081/edit/01React-router 的内置导航访问此 URL 时,它工作正常。路线是<Route path="/edit/:id/" component={EditExpensePage} />.

但是,当我直接将相同的 URL 放入浏览器中时,我在控制台中收到以下两行错误,并且页面不呈现任何内容。

错误

GET http://localhost:8081/edit/bundle.js net::ERR_ABORTED
GET http://localhost:8081/edit/bundle.js 404 (Not Found)
Run Code Online (Sandbox Code Playgroud)

我将感谢您的帮助。

Kra*_*mir 3

发生这种情况是因为您的服务器没有重定向到索引文件。我的意思是http://localhost:8081后面是什么?是节点吗?您确定每个请求都以相同的方式处理吗?

您还可以检查如何包含您的bundle.js. 路径是相对路径./assets/js/bundle.js还是绝对路径/assets/js/bundle.js?应该是绝对的。