- The react-router package is the official package used for routing in React apps and therefore, the only option.
- Yes, react-router is the official React routing solution.
- No, react-router is one of several routing options and you should spend time looking at each of them.
- No, react-router is the de facto routing solution for React and you should use it unless you have a strong reason not to.
- What's the difference between Route and Router components?
- A Route is used to render components based on URL matches and a Router is used to declare route-component mappings.
- There is no difference.
- A Router should be declared by every component, to declare the routes used by the component.
- How do you change only certain parts of the UI as the route changes?
- You can't change only certain parts, you have to re-render the entire component tree, starting at the root.
- You use Route components to render content that is specific to any given section, based on the provided path property. You can have more than one Route with the same path value.
- You pass section names as property values to Route components, along with the component to render for that section.
- When should you use the NavLink component?
- When you want react-router to automatically style active links for you.
- To show the user which links are navigation links versus regular links.
- When you want to use the activeStyle or activeClassName properties to style active links.
- How do you get values from URL paths?
- You can get the value of any URL path segment by passing the index of the segment.
- You have to parse the URL yourself and find the value.
- You use the : syntax to specify that this is a variable and react-router will pass this value into your component as a property.