-6ren">
gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 14:44:30 24 4
gpt4 key购买 nike

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

import { useRouter } from "next/router";

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

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

最佳答案

这是/pages 中页面的路径。
本来是有区别的,但是随着版本的上去,router.query的功能改变了,差异不再存在。
过去route : String - 当前路线pathname : String - 当前路径不包括查询字符串

这个解释从 api 文档中消失了。
https://github.com/vercel/next.js/commit/18d8c90c3f9bead7ac478f6c9a32bdb5d2591832#diff-129f17bae1a499f319a70b9e5821656cbe48f7b66363d653ab2bfa18e210bdce

关于javascript - nextjs中router.pathname和router.route的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65370486/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com