I am working on Reactjs and using nextjs,Right now i am trying to refresh page (using routes) but i am getting following error
Error: No router instance found. you should only use "next/router" inside the client side of your app.
Here is my current code
const Post = ({ post, blogs }) => {
const routers = useRouter();
var spath=routers.asPath;
routers.push({ pathname: spath, query: '' });
})
CodePudding user response:
You probably used router outside of a functional component or hook. Convert Post to hook and it should work.
CodePudding user response:
If you are running this code on application load or on any data change. You should do this inside useEffect
hook because while rendering application on sever router
won't be there and useEffect
runs only inside browser.