Search code examples
reactjsreact-hookshookrouter

How to get the current url path using hook router in react?


I'm new to react and react hooks. I'm using hookrouter package and I tried to googling about the question, but didn't find much about it.

What I want?

I'm trying to get the current url path. For e.g. for https://example.com/users/temp, I want to get /users/temp.

Any help will be appreciated. Thanks in advance!


Solution

  • I finally found on github doc.

    import {usePath} from 'hookrouter';
    
    const PathLabel = () => {
        const path = usePath();
        return <span>Your current location: {path}</span>;
    }