Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between router.pathname and router.route in nextjs

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

like image 201
JayCodist Avatar asked Dec 18 '22 12:12

JayCodist


1 Answers

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

like image 125
UNW Avatar answered Feb 15 '23 10:02

UNW