Basically, I want to make of NextJS router to access page url and I do this:
import { useRouter } from "next/router";
const SomeComp = props => {
const router = useRouter();
}
However, router
has properties pathname
and route
that both seem to contain the exact "url" of the page when I console.log()
them. I've looked at NextJS docs and and I can't see the difference between the two and whether there's some kind of gotcha I should be aware of in using any of the two in accessing the page url
That is the path of the page in /pages.
Originally there was a difference, but as the version went up, the function of router.query
are changed and the difference was no longer there.
In past
route
: String
- Current route
pathname
: String
- Current path excluding the query string
This explanation disappeared from api documents.
https://github.com/vercel/next.js/commit/18d8c90c3f9bead7ac478f6c9a32bdb5d2591832#diff-129f17bae1a499f319a70b9e5821656cbe48f7b66363d653ab2bfa18e210bdce
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With