为什么 React 路由器的 URL 发生变化,但嵌套路由应用程序中的组件不加载?

huangapple go评论83阅读模式
英文:

why react router url changes but component does not load in my nested router app

问题

"react-router URL changes but the component do not load. my app content lots off the nested router.
see my layout
为什么 React 路由器的 URL 发生变化,但嵌套路由应用程序中的组件不加载?

in this app my main two problem

  1. redirect
  2. component not load

see this gif video what is my problem

<blockquote class="imgur-embed-pub" lang="en" data-id="pGbivBq" data-context="false"><a href="//i.stack.imgur.com/TFsb1.jpg">why react router url changes but component does not load in my nested router app</a></blockquote><script async src="//s.imgur.com/min/embed.js" charset="utf-8"></script>

I share gif video because of my gif size big than 2mb.
in this gif video, you see when clicking on the logout button than not redirect.
second when clicking on the signup button my app not redirect.

plz tell me what is my problem"

英文:

react-router URL changes but the component do not load. my app content lots off the nested router.
see my layout
为什么 React 路由器的 URL 发生变化,但嵌套路由应用程序中的组件不加载?

in this app my main two problem

  1. redirect
  2. component not load

see this gif video what is my problem

<blockquote class="imgur-embed-pub" lang="en" data-id="pGbivBq" data-context="false"><a href="//i.stack.imgur.com/TFsb1.jpg">why react router url changes but component does not load in my nested router app</a></blockquote><script async src="//s.imgur.com/min/embed.js" charset="utf-8"></script>

I share gif video because of my gif size big than 2mb.
in this gif video, you see when clicking on the logout button than not redirect.
second when clicking on the signup button my app not redirect.

plz tell me what is my problem

答案1

得分: 1

你只需将组件包装在withRouter内。

<Route exact path="/mypath" component={withRouter(MyComponent)} />
英文:

You just have to wrap the components inside withRouter.

&lt;Route exact path=&quot;/mypath&quot; component={withRouter(MyComponent)} /&gt;

huangapple
  • 本文由 发表于 2020年1月3日 22:58:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/59580750.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定