How does one get the current route for reach router. In react router one would get that through the params?
The docs don't currently show an example how to do this.
How does one get the current route for reach router. In react router one would get that through the params?
The docs don't currently show an example how to do this.
Use the this.props.location as it's passed down to the component:
Alternatively, use the useLocation
hook (since 1.3.0):
import { useLocation } from "@reach/router"
const useAnalytics = () => {
const location = useLocation()
useEffect(() => {
ga.send(['pageview', location.pathname])
}, [])
}
Use the this.props.location as it's passed down to the component:
You can simply just import useLocation
from @reach/router
and assign it to a const use it in your code as below.
import React from "react";
import { useLocation } from "@reach/router";
const YourPage = () => {
const location = useLocation();
return (
<Page>
<div>{(location.pathname = "/terms/")}</div>
</Page>
);
};
export default YourPage;
© 2022 - 2024 — McMap. All rights reserved.
this.props.location
in your component you have your location details including the current location. – Swedenborgianism