动态路由获得参数
✈️

动态路由获得参数

portfolio/[projectId].js

import { useRouter } from "next/router";

function PortfolioProjectPage() {
	const router = useRouter();
	console.log(router.pathname)// 最新的里面没有这个,得用 usePathName
	constle.log(router.query)
	return (
		<div>hello</div>
	)
}
 
blog/[...slug].js

localhost:3000/blog/whatever/you/want

function about() {
	const router = useRouter();
	console.log(router.query); // { slug: ["whatever", "you", "want"]}
	return (<div>hello</hello>)
}