Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Next.js useRouter
// 🤫The following code is experimental and might break in the future!
// Don't use it if you are using some kind of side-effect patterns like: Helmet, GraphQL or react-side-effect.
import { useRouter } from 'next/router'
function Home() {
const {
// `String` of the actual path (including the query) shows in the browser
asPath,
// `String` Current route
route
// `Function` navigate back
back,
// `Function` prefetch a specific page
prefetch,
// `Function` navigate to a specific page (adds entry to history)
push,
// `Function` navigate to a specific page
replace,
// `Object` current query
query,
// `Function` Reload current page
reload
} = useRouter()
return <div>...</div>;
}
export default Home;
@JCWardle

This comment has been minimized.

Copy link

@JCWardle JCWardle commented Jan 30, 2020

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.