简体   繁体   English

React Router 不渲染具有可变参数的组件

[英]React Router not Rendering Components with Variable Params

I am building a portfolio page, and used Create-react-app as well as a node server to handle API calls.我正在构建一个投资组合页面,并使用 Create-react-app 以及一个节点服务器来处理 API 调用。

Everything was working great in dev, and I went to deploy the application.一切都在开发中运行良好,我去部署应用程序。 This is my first full deployment, and it was... interesting.这是我的第一次全面部署,这很……有趣。 I solved most problems, but I'm having issues solving this last one, which is related to the blog on my site.我解决了大多数问题,但我在解决最后一个问题时遇到了问题,这与我网站上的博客有关。 The blog routing is set up like this: <Route path="/blogposts/:slug" component={BlogPost}/> Well, the only blog I have atm, which should be served at /blogposts/how-i-built-this-site , returns a blank page, my index.html file.博客路由是这样设置的: <Route path="/blogposts/:slug" component={BlogPost}/>嗯,我唯一有atm的博客,应该在/blogposts/how-i-built-this-site ,返回一个空白页,我的 index.html 文件。

Instead of pasting in some code, the easiest solution is probably linking the github, since this is a fairly large project (for me).不是粘贴一些代码,最简单的解决方案可能是链接 github,因为这是一个相当大的项目(对我来说)。

Here is the github: https://github.com/lotg515/portfolio这是github: https : //github.com/lotg515/portfolio

If any more info is needed, please let me know.如果需要更多信息,请告诉我。 If anyone figures this out, they're my hero!如果有人发现了这一点,他们就是我的英雄!

I think you need to wrap your Routes with Switch component.我认为你需要用 Switch 组件包装你的路由。

<Switch>
   <Route ....>
</Switch>

This was solved by adding in the index.html file.这是通过添加 index.html 文件解决的。

Still don't know why this issue occurred, it may have something to do with Othka.还是不知道为什么会出现这个问题,可能跟Othka有关系。 Either way, it is fixed now, which is a win for me.无论哪种方式,它现在都已修复,这对我来说是一场胜利。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM