[英]React Router not loading assets on nested routes in production
I'm setting up a project where I need to have a nested route "/user/:id" where the id is serves as a parameter that I can pass in.我正在建立一个项目,我需要一个嵌套路由“/user/:id”,其中 id 用作我可以传入的参数。
In development mode everything (all components, static assets, etc.) loads properly.在开发模式下,一切(所有组件、static 资产等)都可以正确加载。 However, when I build the react project and serve it in production mode, some of the images are not being loaded and looking for the assets on some nested route off the root domain.
但是,当我构建 react 项目并在生产模式下提供它时,一些图像没有被加载并在根域之外的一些嵌套路由上寻找资产。 (I don't fully understand how react grabs the files to be served, but I've attached images that might give insight into this predicament.) The error in grabbing the assets occur when I visit any site off of the "user" path eg /user/234, /user/23, etc.
(我不完全理解 react 如何抓取要提供的文件,但我附上了可能会深入了解这种困境的图像。)当我访问“用户”路径之外的任何站点时,就会发生抓取资产的错误例如 /user/234、/user/23 等。
Below is an下面是一个
Thank you!谢谢!
Turns out that all I needed to do was add <base href="/">
to the head of my index.html
file!事实证明,我需要做的就是将
<base href="/">
添加到我的index.html
文件的头部!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.