Skip to content

Instantly share code, notes, and snippets.

@julsfelic
Created June 3, 2016 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julsfelic/35eef2689f183697e37328b01d9b037f to your computer and use it in GitHub Desktop.
Save julsfelic/35eef2689f183697e37328b01d9b037f to your computer and use it in GitHub Desktop.
Adding React Router to Implement RESTful Routing

Adding React Router to Implement RESTful Routing

Why would we want RESTful routing for an SPA?

  • Context: Users tend to look at the address bar for context of where they are at in the application.
  • Not all apps fall under the SPA paradigm.
  • Because conventions are nice!

How React Router solves these problems

  • The advent of push state and how it allows us to update the url dynamically.
  • Browser support for push state.
  • React Router allows us to use components to create routes for our application.
  • Nesting routes and associating routes with components
  • Dynamic path variables

Adding React Router to our application

  • Installation
  • Adding React Router to our main.js file

Writing our first route

  • Initial setup
  • Associating a component with a router

More Advanced Example

  • Creating a route that utilizes dynamic path variables
  • Accessing the dynamic path variable within a component

Fallback Routing

  • Creating a simple 404 fallback for unknown paths

Further Resources

  • Links to more learning resources

Final Thoughts

  • Recap of benefits of using React Router
  • Send off!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment