react-router中的 Redirect 组件 出现警告 的解决办法?

在做路由拦截,重定向中 Redirect 组件出现警告:
Warning: You tried to redirect to the same route you're currently on: "/login"

路由拦截组件:
**import React from "react"
import { Route, Redirect } from "react-router"
export default ({ component: Component, ...rest }) => {

return <Route {...rest} render={(props) => {
    const { blcoking } = { ...rest }
    return blcoking ? <Component /> : <Redirect to={{
        pathname: "/login",
        state: { from: `/chat/${props.match.params.roomId}` }//额外参数
    }} />
}} />

}**

全部路由:

   const supportsHistory = 'pushState' in window.history
    return (
        <div>
            <BrowserRouter forceRefresh={!supportsHistory}>
                <div>
                    {this.props.headData.headtypes && <IndexHeader />}
                    <Route render={({ location }) => (
                        <TransitionGroup >
                            <CSSTransition key={location.key} classNames="message" timeout={500}>
                                <div>
                                    <Switch location={location}>
                                        <Route exact path="/" component={home} {...this.props} />
                                        <Route path="/live/:roomId" component={live_detail} {...this.props} />
                                        <Route exact path="/video" component={video_list} />
                                        <Route path="/video/:videoId" component={video_detail} />
                                        <Route exact path="/chat" component={chat_room} />
                                        <Route exact path="/chat/:roomId" component={chat_detail} {...this.props} />
                                        <Route path="/login" component={Login} />
                                        <InterseptRoter blcoking={false} path="/chat/:roomId/detail" component={Details} />

                                    </Switch>

                                </div>
                            </CSSTransition>
                        </TransitionGroup>
                    )}

                    />
                </div>
            </BrowserRouter >
        </div >
    );


  
阅读 4.3k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进