Skip to content

Instantly share code, notes, and snippets.

@AllanSaleh
Last active December 13, 2022 06:55
Show Gist options
  • Save AllanSaleh/8ff7f3e2c21549d110ec02be999cf1c0 to your computer and use it in GitHub Desktop.
Save AllanSaleh/8ff7f3e2c21549d110ec02be999cf1c0 to your computer and use it in GitHub Desktop.
  1. What is a BrowserRouter component? What is the purpose of it?
  2. What is the path property in a route?
  3. What is a param and how can we pass them?
  4. What is Link and why does it have a to attribute?
Copy link

ghost commented Dec 9, 2022

  1. It is a router implementation that uses the HTML5 history API (pushstate, replacestate, and popstate events) to keep your UI in sync with the URL. It is the parent component used to store all other components.
  2. The path property describes the URL this route will handle, like branches.
  3. It is a hook (useParams) We can use the dynamic params as path matched with URL
  4. It allows us to navigate around our application. 'To' is a location descriptor.

@symys
Copy link

symys commented Dec 13, 2022

1- BrowserRouter: It comes with React Router. It is used for to hold current location as clean URLs and it provides navigation between URLs. It has Routes and Route inside itself.
2 - "path" property in a route: There can be multiple routes in an application so each route has a path. Paths represents specific URLs. If users type a specific URL into the browser and if any path of routes matches with this URL, users are redirected to the route that has the matched path.
3- param: param means parameters. If we want to pass params and also be dynamic, useParams hook can be used.
4- Link: It provides to navigate to different routes defined in the application. It can be consider like "a" tag in html. "to" is like "href" in html so "to" shows us where will we go when clicking or selecting this link.

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