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

3 points
Created by:
Dirask JS Member

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)  // '/'

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.

❤️💻 🙂