Blitz: `useRouter()` throws `TypeError: Cannot read property 'asPath' of null`

Created on 29 Nov 2020  路  4Comments  路  Source: blitz-js/blitz

What is the problem?

useRouter() throws TypeError: Cannot read property 'asPath' of null on some pages. I don't really know what is causing it because some pages work and others don't. When I use useRouter() from Next.js everything works fine.
edit: It doesn't work with next/router anymore either so I guess it was just randomly working.

Steps to Reproduce

  1. Create a component that uses useRouter()
  2. Add the component to pages or layout

e.g. In my application, I created a shared Header component with links and I'm using useRouter() to get the path to change the color of the active link.

Versions

Linux 4.19 | linux-x64 | Node: v14.4.0

blitz: 0.26.0 (global)
blitz: 0.26.0 (local)
kinbug needs investigation statutriage

All 4 comments

If it's not working with next/router, then likely a bug in next.js.

You see this in dev or prod or both?

I also got this, it happens with [email protected] but not with [email protected], even though they haven't changed anything with router

I saw this in dev, haven't tested it in prod.

Ok must be a next.js thing then. We don't intercept this

Was this page helpful?
0 / 5 - 0 ratings