profile
viewpoint

Ask questionsUncaught (in promise) Error: No router instance found. You should only use "next/router" inside the client side of your app.

Bug report

Describe the bug

next/router is not working as expected. Instead of redirecting, it is throwing the error mentioned in the title.

To Reproduce

  1. Just setup a new Next.js project by fetching next, react and react-dom.
  2. Create an index.js page with following code
import Router from 'next/router'

export default (props) => {
        Router.push('/hola')

        return  (
            <div>
                Hi
            </div>
        )
}

  1. It will throw this error

Expected behavior

It should show the 404 page as 'hola.js' is not there.

System information

  • OS: Ubuntu 18.10
  • Version of Next.js: 8.0.3
zeit/next.js

Answer questions sagar-gavhane

Hi,

useRouter hook solved my problem. Can you look at Next.js official docs link: https://nextjs.org/docs#userouter

useful!
source:https://uonfu.com/
answerer
Sagar sagar-gavhane Pepper India https://sagar-gavhane.vercel.app/ Software engineer 👨🏻‍💻 loves ❤ to experiment with ideas with React ⚛️ and Node.
Github User Rank List