next.js: Router.push('/') is not working as expected
Bug report
Describe the bug
import React, { Component } from 'react';
import Router from 'next/router';
export default class _error extends Component {
componentDidMount = () => {
Router.push('/');
};
render() {
return <div />;
}
}
This is code inside _error.js. I was expected it would redirect to index.js page but nothing is happening.
The Weird Thing is When I use Router.push('/error', '/');, It pushes to index.js page.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- Make any page.
- Router.push(‘/’)
Expected behavior
Push to index.js page
Screenshots
If applicable, add screenshots to help explain your problem.
System information
- OS: macOS
- Browser Chorme
- Version of Next.js: 7.0.2
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 1
- Comments: 17 (3 by maintainers)
It’s not currently happening to me right now, but when I had this problem, this code worked.
I’m not sure it’s going to work in every page since I used it in _error.js page.
@timneutkens could you please reopen this? It’s a real issue and we currently have it in production
I am having the same issue. Is there a fix for this or can you just not use the Link component in this way?