Friday, August 9, 2019

React Router v4 Tutorial - #2 Routes & Links

Moving on, let's set up React Router in our app. First, we'll need to render the built-in BrowserRouter as the root component in our tree. With the web router in place, we can start adding Link components that will help us navigate around without page reload. Lastly, to match our client-side routes, we'll use the Route component. Define the pathname under the path prop, and then instruct the router to render some content in response to that path being matched, by either supplying it a "render" or a "component" prop.

All three (BrowserRouter, Link, Route) are React components and can be rendered with JSX tags. That means no static routing, no route config files, no hustle. Sweet!

No comments:

Post a Comment