Skip to content

Instantly share code, notes, and snippets.

@jamster10
Last active May 12, 2019 01:37
Show Gist options
  • Save jamster10/81a9b835d3fe3c981b3e32dd900eb451 to your computer and use it in GitHub Desktop.
Save jamster10/81a9b835d3fe3c981b3e32dd900eb451 to your computer and use it in GitHub Desktop.
  1. Wrap the entry point usually index.js

import { BrowserRouter } from 'react-router-dom'

ReactDOM.render(<BrowserRouter><App\></BrowserRouter/>, documnet.querySelector('#root));

  1. SWITCH VS just ROUTES (can use both)

things in switch are exclusive, only the first one gets rendered once matched so order matters. Check documentation for further explanation. Either way place your Routes or switches in place where things can change. for eg in main app you may want to switch between views below your nav. so below your nav you have routes and/or switches. import { Switch, Route } from 'react-router-dom'

  1. LINKS vs NAVLINKS (can use both)

We need to know which route we should follow and when, usually dependent on the user clicking something. Instead of anchor tags we use these. NavLinks add styling to the currently rendered element when the route is matched. For eg you could have a button be underlined when it's pointing to the active path. Links don't have the styling. Keep in mind either way, they become anchor tags in the html when the page is rendered. Cool! You probably want one of these types in your Nav.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment