nextjs中router.pathname和router.route的区别

Jay*_*ist 2 javascript reactjs next.js

基本上,我想使用 NextJS 路由器来访问页面 url,我这样做:

import { useRouter } from "next/router";

const SomeComp = props => {
   const router = useRouter();
}

Run Code Online (Sandbox Code Playgroud)

但是,router具有属性,pathname并且route当我使用console.log()它们时,它们似乎都包含页面的确切“url” 。我查看了 NextJS 文档,但看不到两者之间的区别,以及在使用这两者中的任何一个访问页面 url 时是否应该注意某种问题

UNW*_*UNW 7

这是/pages 中页面的路径。

本来是有区别的,但是随着版本的升级,功能router.query都变了,区别就没有了。

过去

route: String- 当前路线

pathname: String- 不包括查询字符串的当前路径


这个解释从 api 文档中消失了。

https://github.com/vercel/next.js/commit/18d8c90c3f9bead7ac478f6c9a32bdb5d2591832#diff-129f17bae1a499f319a70b9e5821656cbe48f7b66382d0fa