Why You Get "Router May Have only One Child Element" Warning ?

In this brief guide, We will share Why You Get "Router May Have only One Child Element" Warning.

You have to wrap your Route's in a <Switch> block because <Switch> is unique in that it renders a route exclusively.

At first you need to add Switch to your imports:

import { Switch, Router, Route } from 'react-router'

Then define the routes within <Switch> block:

<Router>
  <Switch>
    <Route {/* ... */} />
    <Route {/* ... */} />
  </Switch>
</Router>

Link: https://github.com/sudheerj/reactjs-interview-questions

#react #reactjs #javascript

What is GEEK

Buddha Community

Why You Get "Router May Have only One Child Element" Warning ?

Why You Get "Router May Have only One Child Element" Warning ?

In this brief guide, We will share Why You Get "Router May Have only One Child Element" Warning.

You have to wrap your Route's in a <Switch> block because <Switch> is unique in that it renders a route exclusively.

At first you need to add Switch to your imports:

import { Switch, Router, Route } from 'react-router'

Then define the routes within <Switch> block:

<Router>
  <Switch>
    <Route {/* ... */} />
    <Route {/* ... */} />
  </Switch>
</Router>

Link: https://github.com/sudheerj/reactjs-interview-questions

#react #reactjs #javascript