A warning appears in the Redirect component during route interception and redirection:
Warning: You tried to redirect to the same route you"re currently on: "/ login"
Route blocking component:
* * 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}` }//
}} />
}} />
} * *
all routes:
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 >
);