Getting the current route path in Gatsby
In this post we will give you information about Getting the current route path in Gatsby. Hear we will give you detail about Getting the current route path in GatsbyAnd how to use it also give you demo for it if it is necessary.
we are going to learn about how to get the current route path from aURL in Gatsby.
Gatsby uses the @react/router package behind the scenes to handle the routes, which passes a location object to the all routes we created inside the pages directory, which is holding the details about the current route we are in.
Consider, we have the following route in our gatsby app.
localhost:8000/about
To get the route path from an above URL, we need to use the props.location.pathname property inside the About component.
import React from "react";export default function About(props) { const { location } = props; const pathname = location.pathname; return ( <div> <h1>This About Page</h1> <p>{pathname}</p> // path is /about </div> );}
Hope this code and post will helped you for implement Getting the current route path in Gatsby. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs