Skip to content

Instantly share code, notes, and snippets.

@dahyun31x
Created September 25, 2021 12:19
Show Gist options
  • Save dahyun31x/c3395d1b47c0867cee3741c14dda86c2 to your computer and use it in GitHub Desktop.
Save dahyun31x/c3395d1b47c0867cee3741c14dda86c2 to your computer and use it in GitHub Desktop.
[Next.js] 페이지의 일부분만 라우팅하기
import { useRouter } from 'next/router'
import Link from 'next/link'
export default function TabsPage() {
const router = useRouter()
const tab = router.query.tab || 0
return <div>
<ul>
<li><Link shallow href={{ pathname: '/tabs', query: { tab: 0 } }}>Tab 0</Link></li>
<li><Link shallow href={{ pathname: '/tabs', query: { tab: 1 } }}>Tab 1</Link></li>
<li><Link shallow href={{ pathname: '/tabs', query: { tab: 2 } }}>Tab 2</Link></li>
</ul>
<p>Selected tab: {tab}</p>
</div>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment