Skip to content

Instantly share code, notes, and snippets.

@HaNdTriX
Last active June 10, 2020 02:20
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HaNdTriX/b66e30851c2bc3fbc4ee48b4473e2321 to your computer and use it in GitHub Desktop.
Save HaNdTriX/b66e30851c2bc3fbc4ee48b4473e2321 to your computer and use it in GitHub Desktop.
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
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment