Languages
[Edit]
EN

React / react-router - how to see which route we are on?

3 points
Created by:
Nathanial-Donald
404

In this article, we would like to show you how to see which route we are on in react-router.

Quick solution:

import { useLocation } from 'react-router-dom'

const App = () => {
  const location = useLocation();
  console.log(location.pathname)  // '/'
}

Alternative titles

  1. React / react-router - useLocation
  2. React / react-router - how to check which route we are on?
  3. React / react-router - current path
  4. React / react-router - current pathname
  5. React / react-router - current location
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

React - react-router

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join