2019年3月31日 星期日

React: Switch

Usage: To route for only one component in the Switch tag.




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

...

<Router history={history}>
  <div>
    <Header />
    <Switch>
      <Route path="/" exact component={StreamList} />
      <Route path="/streams/new" exact component={StreamCreate} />
      <Route path="/streams/edit/:id" exact component={StreamEdit} />
      <Route path="/streams/delete/:id" exact component={StreamDelete} />
      <Route path="/streams/:id" exact component={StreamShow} />
    </Switch>
  </div>
</Router>


沒有留言:

張貼留言

Git: How to clone only part of the repo (specific directory)

 https://stackoverflow.com/a/60729017/5721873