I keep getting the warning Warning: You tried to redirect to the same route you're currently on
when trying to navigate to /articles/<article_id>/details
.
I currently have the following routes:
/
/settings
/settings/connections
/articles
/articles/:article_id
/articles/:article_id/:author_id
/articles/:article_id/:author_id/details
/login
/logout
Here is what my main Switch
looks like:
<Router>
<Switch>
<Route path="/articles" component={Articles} />
<Route path="/settings" component={Settings} />
<Route path="/login" component={Login} />
<Route path="/logout" component={Logout} />
<Redirect from="/" to="/articles" exact />
<Route component={NotFound} />
</Switch>
</Router>
Then in Articles.js
I have another Switch
.
<Switch>
<Route path="/articles/:article_id/details" component={ArticleDetail} />
<Route path="/articles/:article_id/authors" component={ArticleAuthors} />
<Route path="/articles/:article_id/authors/:author_id" component={ArticleAuthor} />
<Route path="/articles/:article_id/authors/:author_id/details" component={ArticleAuthorDetails} />
<Redirect from="/articles/:article_id" to="/articles/:article_id/details" exact />
</Switch>
Here's the issue:
When I navigate to /articles/<article_id>/details
manually, I get the aforementioned warning. I've tried to manually check if the current route is on /articles/<article_id>
or /articles/<article_id>/
before redirecting, but this seems hacky/wrong.
Is there an easier way to achieve what I'm trying to do? Or am I misusing react router?