I'm not sure this is a bug, but it throws an error and it probably shouldn't.
Shallow routing following the docs throws TypeError:
Unhandled Rejection (TypeError): Cannot read property 'auth' of null
Clone repo and run:
https://github.com/tgdn/nextjs-shallow-typeerror/
Error should not be thrown.
This might be a documentation issue. In the example in this repo the second parameter is the same as the first (the url).
So I was able to get shallow routing to work via router.push('/?count=1', '/?count=1', { shallow: true })
I believe this line in the Next codebase would prevent null from being a second valid parameter. typeof null === 'Object'so formatWithValidation(_as) runs.
I ended up using the same url as the first two arguments to push as you just said.
It probably is a documentation issue indeed.
@tgdn @jamesmosier I came across the same issue while following the docs. I think the problem comes from here where as is initiated to url (typeof null return always object), and because passing null is different from undefined for the behaviour of default parameter value(see here) , as parameter doesn't get url value when initiated to null.
@timneutkens I can see 2 possibilities here:
undefined instead of null: router.push('/?counter=10', undefined, { shallow: true })null check for as parameter in push function (maybe also in replace function), something like this in router.ts: push(url: Url, as: Url = url, options = {}) {
return this.change('pushState', url, as === null ? url : as, options)
}
I would be happy to submit a PR with either of these solutions 馃槉
I came across the same problem in the docs and I found this issue, so I created a small PR to update the docs 馃槂