Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react router switch

import { Route, Switch } from "react-router";

let routes = (
  <Switch>
    <Route exact path="/">
      <Home />
    </Route>
    <Route path="/about">
      <About />
    </Route>
    <Route path="/:user">
      <User />
    </Route>
    <Route>
      <NoMatch />
    </Route>
  </Switch>
);


# Now, if we’re at /about, <Switch> will start looking for a matching <Route>. 
# <Route path="/about"/> will match and <Switch> will stop looking for matches and render <About>. 
# Similarly, if we’re at /michael then <User> will render.
Source by v5.reactrouter.com #
 
PREVIOUS NEXT
Tagged: #react #router #switch
ADD COMMENT
Topic
Name
1+1 =