Next.js: Router.push('/') is not routing back to my page/index.js file.

Created on 4 Sep 2019  路  6Comments  路  Source: vercel/next.js

Bug report

Describe the bug

Simple javascript function to Router.push("/") will not work correctly.

in _app.js has:

Router.events.on('routeChangeStart', url => {
  console.log(`Loading: ${url}`);
});

which is working...

in my AppBar(Material-ui Toolbar) i have a simple onClick (i've also tried with <Link> to no avail)

<Avatar
            src="/static/img/favicon-96x96.png"
            onClick={() => Router.push(ROUTE.LANDING)}
          />

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

Create a new <Link> with href to "/" ....see if it redirects to your homepage from another page.
or
Create a new element with an onChange parameter. onChange={Router.push("/")} and see if it redirects to home page from another page.
The current page will stay rendered, however the routeChangeStart callback will fire...

Expected behavior

I expect the home page (index.js) to be rendered within a few seconds of calling Router.push or clicking a <Link> with href="/"

Screenshots

image

image of the routeChangeStart consoling out in _app.js

System information

  • OS: both macOS and Windows
  • i've tested with Firefox, Chrome, and Safari.
  • "next": "^9.0.5"

Additional context

Reopening from #5264 .

Thank you!

Most helpful comment

https://github.com/zeit/next.js/blob/canary/CODE_OF_CONDUCT.md

Specifically:

Examples of unacceptable behavior by participants include:
Trolling, insulting/derogatory comments, and personal or political attacks

Dude do you have OCD with closing issues?

This falls under insulting/derogatory comments.


This is not a bug in Next.js itself. It's a problem in webpack and there's 2 open issues as @ijjk outlined. So there is no reason to keep this issue open.

It's already on the roadmap to be fixed, see https://github.com/zeit/next.js/issues/8626

This issue by itself is not reproducible based on the steps provided.

All 6 comments

Hi, are you using next-css and importing CSS files outside of _app? If so this is a duplicate of #7886 and https://github.com/zeit/next-plugins/issues/282

OMG thanks! I believe I'm calling the css file from _app. But I'll research the referenced issue and investigate my code thoroughly.

Please allow me a few hours to close this out myself and document accordingly.

馃檹馃徑

If you're using next-css it's definitely the same as https://github.com/zeit/next-plugins/issues/282

So I'll close this issue and we're already tracking it there.

Dude do you have OCD with closing issues? I just asked for a little time to verify that this was indeed the issue, you closed this without verifying anything....

https://github.com/zeit/next.js/blob/canary/CODE_OF_CONDUCT.md

Specifically:

Examples of unacceptable behavior by participants include:
Trolling, insulting/derogatory comments, and personal or political attacks

Dude do you have OCD with closing issues?

This falls under insulting/derogatory comments.


This is not a bug in Next.js itself. It's a problem in webpack and there's 2 open issues as @ijjk outlined. So there is no reason to keep this issue open.

It's already on the roadmap to be fixed, see https://github.com/zeit/next.js/issues/8626

This issue by itself is not reproducible based on the steps provided.

I fixed it with Router.push('/', '/')

Was this page helpful?
0 / 5 - 0 ratings