score:6
The Switch
component will only render its first match.
The first Route
that matches the path /users/10
is <Route path="/users" component={Users} />
.
This means that even though you have a second Route
that says the "10" should be a param called id
, its ignoring it and treating it as the first Route
does which has no params.
You can easily correct this behavior by using the exact
prop on the first Route
:
<Route exact path="/users" component={Users} />
This will instruct react-router
to only match that route if the URL matches the path
exactly, and will allow /users/10
to pass down to the Route
you actually want it to match. Then you will have the params available that you expect.
Source: stackoverflow.com
Related Query
- Reactjs react router dom useParams not working with dynamic url
- React Router v6 not working with URL Slugs
- React Router dom is not working when I hosted my React App with github pages?
- React router dom v6 using useNevigation is not working with redux
- React Router with custom history not working
- React router v4 not working with Redux
- React Native Image Not Working with specific URL
- Can not pass state with react router dom v6 beta, state is null
- React router not working with params
- Sending state with react router not working
- Material UI AppBar with React Router 4 Implementation not working
- Bootstrap dropdown not working with React router
- Routes are not working with React router v4
- react router dom not working when changing the path
- React router v4 broswer history not working with code splitting
- Redirect with state not working in React Router 4.x
- React Router not working when URL contains multiple paths
- React router dom (6.0.1) child route not working properly
- Nested routes with react router v4 not working
- Protected Routes React Router 4 not working with auth state stored in Redux
- React Router / Redux / HOC not working with 'render' prop
- Nested Route not working in react router dom for my admin dashboard
- My 404 not found page with React router is not working
- React Router not working correctly on production with express backend
- ReactJS - React Router not changing component but url is changing
- MenuItem with dynamic value is not working in Material UI React
- React Router not working with Github Pages
- dynamic routing with reactjs not working
- Reactjs dynamic classname with react router
- React router dom navigate method is not working properly
More Query from same tag
- How to catch exception in JSX
- React 404 Heroku Issue
- ReactJS: execute code after .map() statement with ajax call in it is finished
- How to fix 'Cannot set property 'props' of undefined' error
- React binding function
- How can I access the props when the page loads?
- Control html dynamically without component re rendering in React with Apollo
- Fixing 'define' is not defined no-undef in react create app third party imports
- react select is not picking up my selected value using typescript
- ReactJs What is the difference between calling {this.functionName} and {this.functionName()}
- how to add inline style width:calc(100% / var) in reactjs?
- Navigating to a 404 Route with Reach Router
- TypeScript error - property component does not exist on React mui MenuItem
- Flattening object and limitting number of nesting
- How to display default and props values in react js?
- TypeError: Cannot read property 'name' of null in react with redux
- How to pass props to a non rendered function in React?
- Winterfell - how to set custom validation message
- How to take input value from submit form and store in redux store variable?
- ts-loader not working (You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file)
- Can we generate object with jsx fields?
- How to skip validation for last object in fieldArray form using yup validation schema with react-hook-form?
- react extract proptypes, isRequired and defaultProps from component
- Is the parent object reference changed if a child object is changed?
- React JS: Use environment variables to specify two API urls based on production vs development
- TypeError: Cannot read properties of undefined (reading 'map') whole component code is not working
- Using react-i18next within a class component
- Delete object from Firebase, React, ES6
- Transform the string of all my objects into an array
- Flex spacing for horizontal components in React JS