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.

Impoving react-router-config

See original GitHub issue

I have 2 features to propose:

  1. Do not force users to use renderRoutes inside components. Instead of that renderRoutes can be something like this:
<route.component {...props} {...extraProps} route={route}>
    {renderRoutes(route.routes)}
</route.component>

Minus one dependency in component. 2. Render routes by itself if no component was passed

{route.component && (
    <route.component {...props} {...extraProps} route={route}>
        {renderRoutes(route.routes)}
    </route.component>
)}
{!route.component && (
     {renderRoutes(route.routes)}
)}

That will help if I configure router not in one file.

const routes = [{
    path: '/',
    component: App,
    routes: [{
        path: '/bar',
        routes: require('./bar)
      }, {
        path: '/baz',
        routes: require('./baz')
    }]
}];

Files bar.js and baz.js export some routes structure.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
timdorrcommented, Feb 12, 2018

Ah, I see what you are saying. The main issue is related to the refactor I mentioned. We’re basically just wrapping a <Switch> at the moment and I would like to refactor to wrap matchRoutes instead, allowing us to traverse the entire tree and back out of subtrees as well. This is all related to a big refactor of renderRoutes.

0reactions
dimitriirybakovcommented, Feb 12, 2018
  1. Of course you need call renderRoutes once in root of your app like this.
ReactDOM.render((
  <BrowserRouter>
    {renderRoutes(routes)}
  </BrowserRouter>
), document.getElementById('root'))

But why do I need to use it in other components? Why can’t renderRoute render it by itself and pass rendered children to my component?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Handle Routing in React Apps with React Router
In this tutorial, you'll install and configure React Router, build a set of routes, and connect to them using the <Link> component.
Read more >
Upgrading from v5 v6.6.1 - React Router
For this step, you'll need to install React Router v6. If you're managing dependencies via npm: $ npm install react-router-dom # or, for...
Read more >
8 Basic and Advanced React Router Tips | by Martin Novak
Introduction to React Router. React routes use the package react-router-dom , so start by installing it: · React Router in App.js · React...
Read more >
Improving performance through better architecture - Atlassian
The router is powered by a static routes configuration array. This array must be provided to the router as a prop. Each route...
Read more >
React Router DOM: How to handle routing in web apps
These applications are easy to deploy and greatly improve the user ... Because we are creating a web app, let's install react-router-dom :...
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