I'm trying to figure out if this is a react-router thing or just a React thing. I am talking about the $ here in their example:
react-router API
<Link to={`/users/${user.id}`} activeClassName="current">{user.name}</Link>
is the ${}
a react thing? and if so what do you call it?
Using an asterisk ( * )To set up a default page in React Router, pass an asterisk ( * ) to the Route 's path prop: <Switch> <Route exact path="/" component={Home} /> <Route path="/messages" component={Messages} /> <Route path="/about" component={About} /> <Route path="*" component={Home} /> </Switch>
React Router is a standard library for routing in React. It enables navigation between views from different components in a React application, allows the browser URL to be changed, and keeps the UI in sync with the URL.
Routing is a process in which a user is directed to different pages based on their action or request. ReactJS Router is mainly used for developing Single Page Web Applications. React Router is used to define multiple routes in the application.
Use the useParams() hook to get the ID from a URL in React, e.g. const params = useParams() . The useParams hook returns an object of key-value pairs of the dynamic params from the current URL that were matched by the Route path.
This is not a React thing.
This is a JavaScript ES6 feature:
The old way to concatenate a string :
var user = 'abc' + myuser;
ES6:
var user = `abc${myuser}`;
${variableName}
inside backticks is just part of es6's string interpolation system that simply just embeds the value of a variable in the given string.
For more docs and examples see MDN - Template Literals
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With