question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react-router-config does not match on later paths even if there is an exact path match later

See original GitHub issue

Version

4.1.1

Test Case

None

Steps to reproduce

Create a react-router-config that has the following:

    [{ component: someAuthorizedLayout
        routes: [
            {component: AuthorizedDashboard, path: '/home, exact: true}
       ]
     },
     { component: UnauthorizedLayout
         routes: [
            {component: Login, path: '/', exact: true}
        ]
     }]

Try to go to ‘/’ and you are unable to. Why? Because the route matches the first route and “consumes” the request before it realizes that there is a ‘/’ exact match

Expected Behavior

I expect it to go to the Login page.

Actual Behavior

It goes to no route because it traverses the routes tree and when it hits someAuthorizedLayout it finds no nested routes that match.

Is this a bug? or is this by design?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

13reactions
timdorrcommented, Nov 27, 2017

This does appear to be a bug in rrc. We’re not doing any testing of that form of routes, so the first step would be to add a failing test. Then we can go about fixing for it.

Edit: Why are people thumbs-downing me? 😭

1reaction
mjacksoncommented, Oct 10, 2018

I believe renderRoutes should not be using a <Switch> internally, but rather should return an array of <Route> elements.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-router-config does not match on later paths even if there ...
It goes to no route because it traverses the routes tree and when it hits someAuthorizedLayout it finds no nested routes that match....
Read more >
react-router render menu when path does not match
It will only run the first matching Route and routes without a path attribute match anything. <div> <Switch> <Route exact path="/" render={props ...
Read more >
Match - React Router: Declarative Routing for React.js
A <Route> that uses the children prop will call its children function even when the route's path does not match the current location....
Read more >
React Router - Testing Library
This example demonstrates React Router v6. For previous versions see below. // app.js import React from 'react' import {Link, Route, Routes, ...
Read more >
ReactJS | Router - GeeksforGeeks
1.exact: It is used to match the exact value with the URL. For Eg., exact path='/about' will only render the component if it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found