React-Router 重新渲染了错误的组件
React-Router re renders the wrong component
我设置的路由无法正常运行。
他们可能会转到组件并提及正确的路线,但是当我手动编写 URL 时,它最终会重新呈现到主页或 localhost:3001/login。
你知道为什么会这样吗? enter image description here
您已经为两个不同的组件定义了相同的路由,这可能就是问题所在。
<Route exact path="/" component={Charges} />
<Route exact path="/" component={Account} />
顺便说一句,这不是授权路由的理想方式。尝试这样的事情
<Route path="/account" render={() => (isAuth() ? (<Redirect to="/login"/>) : (<Account />))}/>
哪里是 isAuth() 是一个 returns 布尔值
的函数
isAuth() => {this.props.isAuth};
如果 isAuth() return 为真,这将呈现帐户组件,否则它将重定向到登录。
看起来你有 <Redirect to="/login"/>
应该是导致错误的原因。
我设置的路由无法正常运行。 他们可能会转到组件并提及正确的路线,但是当我手动编写 URL 时,它最终会重新呈现到主页或 localhost:3001/login。 你知道为什么会这样吗? enter image description here
您已经为两个不同的组件定义了相同的路由,这可能就是问题所在。
<Route exact path="/" component={Charges} />
<Route exact path="/" component={Account} />
顺便说一句,这不是授权路由的理想方式。尝试这样的事情
<Route path="/account" render={() => (isAuth() ? (<Redirect to="/login"/>) : (<Account />))}/>
哪里是 isAuth() 是一个 returns 布尔值
的函数isAuth() => {this.props.isAuth};
如果 isAuth() return 为真,这将呈现帐户组件,否则它将重定向到登录。
看起来你有 <Redirect to="/login"/>
应该是导致错误的原因。