score:1
Accepted answer
You can make use of url path parameters to specify multiple paths matching the same route.
In your case the Route will look like
<Route path = "/test/:param/id-1" component={MyComponent}/>
In case you only want to match the /orders/ids-1
and /products/id-1
, then you can make use of regex in the path param. react-router
makes use of a path that path-to-regexp
understands,
The relevant documentation of it is there with the react-router documentation
So you can use
<Route path = "/test/(orders|products)/id-1" component={MyComponent}/>
Source: stackoverflow.com
Related Query
- react router v4 about how to match two url with one route and one component
- How to click a button and navigate to a new route with URL params using React Router 4
- Im using React Router and I want one of my route links with path="/" to be the home page on reload.. How can you do that?
- How to pass the match when using render in Route component from react router (v4)
- React Router V4: How to render a modal in the same screen changing only the url and then with that url, be able to rebuild the whole screen
- React router 4 `Link` component only changing the url and not updating the route
- How to test a React component that has Router, Redux and two HOCs... with Jest and Enzyme?
- How to 1). put a div , 2). render a component without Route inside <Routes> with React Router in v6 React?
- How to match ambiguous path and static path with React Router
- How to set active only one link with react router for multiple url state?
- How to route correctly with a mixture of parent and child routes with React Router
- How to use Typescript with React Router and match
- React Router v6 : How to render multiple component inside and outside a div with the same path
- How to link to Routes inside the component rendered by another Route with React Router
- How to best handle the state of one component used by two urls (1 sub url) in React / Router
- How to create a new page and route programatically in React.js with React Router
- How to pass data to another component not in the URL with React Router
- How can I pass props from one component to another using Link and router in react
- How to programatically go one level up of the route hierarchy with React router 5?
- How to create multiple swiper instance in a react component and control one with the swipe of another?
- For a component in React with Reux, how to not fire mouse event in one case and how to fire mouse event in another case
- How to highlight two Menu.Item each in separate component in ANTD with React Router {pathname}
- How to extract props and states from one sibling component to another with react hooks?
- How do I pass Redux props to a separate component in a different Route with React Router v4?
- How to Use URL Parameters and Query Strings With React Router
- How to make same URL scheme but different route and component in React JS
- How to mock React component methods with jest and enzyme
- How to make react router work with static assets, html5 mode, history API and nested routes?
- How do I export more than one class component with React JS?
- How do you test router match params with jest and enzyme?
More Query from same tag
- Next.js CORS blocking using Vercel
- Twilio.js:264 Uncaught TypeError: url.URL is not a constructor
- How to display TimeStamp (received as Epoch) from Axios json response in human readable form?
- Call async method and use its response inside useRef in React
- Data/model managing in React Router / Redux application
- How to print html text depending on condition using reactJs?
- Material Design React Multiple Select Placeholder
- React state update not reflecting
- Serve static react app with nodejs through docker
- How to clearInterval on componentWillUnmount() correctly in react?
- React.js - ErrorBoundary
- React Hooks: accessing state across functions without changing event handler function references
- How to make form not refresh with custom submit button in React
- Why JSON object isn't being stored properly?
- What takes place where in reactjs build system?
- How to put new object into array of objects in state
- What is the correct syntax inside the src property in a img tag for a mapped json file using ReactJS?
- How can I communicate between related react components?
- d3-delaunay lines not showing
- Chaining promises including fetch
- ReactJS.NET - Bundles - TinyIoCResolutionException: Unable to resolve type: React.IReactEnvironment
- Resetting form fields to initial state in React
- How to pass props to child from parent with a map
- React Hooks Exhaustive-deps async infinite Loop
- React Toggle Menu
- React - Use JSON to store data
- Import default react component with two or more different name
- how to 'redirect' with react after login with passport.js?
- Change a value in a table by clicking on it
- How to test this line in React with Jest?