a component provided by react-router-dom
it used in parent Element
it is used to render child elements using path
it is a function provided by react-router-dom
used to render children
takes array of route objects
it contains default element and it's path along with array of objects of child elements as children
RouterProvider is a component provided by React Router that allows you to specify which router your application should use. It takes the router instance created by functions like createBrowserRouter and makes it available throughout your application, enabling navigation and routing functionalities.
root.render(
it takes tha path from appRoute and renders that linked path when clicked that element.
Syntax ----> import RestaurantCard, { withPromotedLabel } from "./RestaurantCard";
const RestaurantCardPromoted = withPromotedLabel(RestaurantCard);
{dis !== 0 ? <RestaurantCardPromoted resData={restaurant} /> : <RestaurantCard resData={restaurant} />}
-------|---------------------------|--------------------------------------------------------------|
| RestaurantCard Component | (additional function) |
-------|---------------------------|--------------------------------------------------------------|
export const withPromotedLabel = (RestaurantCard) => {
return (props) =>{
return (
<div className="relative">
<label className="absolute top-1 left-0 bg-red-600 text-white px-5 py-1 rounded-xl">Flat Deal</label>
<RestaurantCard {...props} />
</div>
);
};
};
{
//fallback is necessay to show the piece of JSX till the time it doesn't load the component
path:"/grocery",
element:<Suspense fallback={<Shimmer />}><Grocery/></Suspense>,
},
{
//giving dynamic restaurant id for fetching reastaurant's menu
//importing restaurant menu component
************* COLON ************
path:"/restaurant/:resId",
element:<RestaurantMenu/>
********************************
},
{
path:"/cart",
element:<Cart/>
}
REASON -----> The colon (:) before resId indicates that this part of the URL is a placeholder for a dynamic value.
When a URL matches the pattern, React Router will extract the value of resId from the URL and make it available to the RestaurantMenu component via the route parameters.The useParams hook allows us to access URL parameters within our components. It retrieves the value of the parameter specified in the route and makes it available for further use. By leveraging this hook, we can create dynamic routes and display content based on the URL.
IN APP.JS**************************************
path:"/restaurant/:resId", // redId is used. it means this is a parameter used in URL for fetching
element:
******************************************************
HOW DYNAMIC RESID IS USED (IN BODY.JS)*********************
<Link key={restaurant?.info?.id} to={/restaurant/${restaurant?.info?.id}
}>
{/* rendering restaurantCard information to restaurantCard component */}
{dis !== 0 ?
EXTRACTING DYNAMIC RES ID PASSES (IN RESTAURANTMENU.JS)******** const { resId } = useParams();
https://nominatim.openstreetmap.org/search?q={city name}&format=json