score:1
Accepted answer
you can get the routes
in an array by using below library
https://github.com/alansouzati/react-router-to-array
import react from 'react';
import { route, indexroute } from 'react-router';
import reactroutertoarray from 'react-router-to-array';
// or var reactroutertoarray = require('react-router-to-array');
console.log(reactroutertoarray(
<route path="/" component={fakecomponent}>
{/* just to test comments */}
<indexroute component={fakecomponent} />
<route path="about" component={fakecomponent}>
<route path="home" component={fakecomponent} />
<route path="/home/:userid" component={fakecomponent} />
</route>
<route path="users" component={fakecomponent} />
<route path="*" component={fakecomponent} />
</route>)
); //outputs: ['/', '/about', '/about/home', '/users']
Source: stackoverflow.com
Related Query
- React show routes if set up using react-router
- Accessing Redux Store from routes set up via React Router
- Conditionally set active class on menu using react router current route
- React router activeClassName doesnt set active class for child routes
- React set state/props on route using react router
- Show Sidebar Navigation only at Home using React Router Dom
- Using the same component for different Routes with React Router
- how to show details page using react router dom
- Redirect to a page that only show the contents of a component/page using React Router
- React router only show Navigation component if the current path is on any of the valid routes
- Protected Routes in React Router v6, using useState, but always returns false
- React Router - routes not working using a Fragment
- React Router routes but show error message
- React Router v6 - Using NavLink but getting No routes matched location "/"
- Why is my React Authentication component using AWS Amplify being rendered infinitely when using React Router V6 to protect routes
- Sharing state across React router v6 routes using Context API
- Using REACT ROUTER 4 nested Routes are coming blank
- Is it possible to create nested routes with multiple levels using react router dom
- How to set relative paths using React Router in an existing ASP.NET Core app that is using MVC
- form using React hook form and redux toolkit. then routes in react router dom
- How to nest routes using react router dom
- How to setup Routes using React Router in my ReactJS app?
- React router renders blank page using exact on all routes
- react router - properly using links inside nested routes
- Nested routes won't work using React Router 6
- How to make routes private using react router
- React router sidebar routes correctly but doesn't show the component under the top menu
- Using React Router with Switch and can't get the page to render different components when changing routes
- How can I create multiple routes using React Router v4 (Sidebar)?
- Create a unique show page for 151 different profiles using react router
More Query from same tag
- react: strange behaviour on hover
- add scroll listener by id
- How to retrieve a fetch data from a JSON?
- React redux and React router,link change does not re render view
- Login Security using jsonwebtoken
- State value from one React class used in another React class
- npx create-react-app client gives this error "Cannot read properties of undefined (reading 'isServer')"
- how to fix CORS problem in node and react app with socket.io
- must be wrapped in an enclosing tag
- How to bind keyboard events with div elements in React
- Error when run the test "Cannot find module "
- Including local JS and CSS files using Gatsbyjs
- Complex state not updating correctly
- ColorPicker material-ui-color, set color on mouse up
- Filter an Array through id and then mapping through a nested array inside
- How to pass an object as props to a child Functional Component in React.js?
- React: How to display Firestore subcollection
- Nested flexbox is overflowing screen
- How do I make my web app's main page look different depending on whether the user signed in
- Flow - how to use declared type in another type?
- Displaying Div with Child and Parent state values
- Configuring Cypress, cypress-react-unit-test, and React
- ReactJS many tables from one data array/json/request from DB
- How to change props after submit and pass value to another component?
- Stuck on adding image url and normal url in props
- Remove input fields except one React
- React ES6 alternative for mixins
- How to read cookies with react?
- Leaflet GeoJSON Turf: × Error: Invalid LatLng object: (undefined, undefined)
- Typeerror : failed to fetch while Uploading file in SharePoint using pnpjs