2

For the past few months we've been working on a website based on Next.js with great joy. It all worked splendidly and had no big problems. However as of yesterday we're suddenly getting an error on the production version when applying a router.push: Cannot read property 'url' of undefined. The router.push in question is as follows:

router.push(
{
   pathname: `/catalogus/category=${filters.category[soortSelected].slug}`,
},
undefined,
{ scroll: false }
);

The function where it goes wrong is called formatUrl, but I have no real clue as to it's purpose (apart from the obvious function name of course). It get's a urlObj as parameter, but where that comes from, I have no clue either. The strange thing is, even reversing to an old commit does not seem to help, which is just baffeling to me.

EDIT: Apparently it has something to do with the locale, as it only breaks on the 'defaultLocale' version and not any other language.

1
  • 1
    the question and code does not shows similarity, this is not how you post a question Please visit the help center, take the tour to see what and How to Ask. Do some research, search for related topics on SO; if you get stuck, post a minimal reproducible example of your attempt, noting input and expected output using the [<>] snippet editor. Commented Feb 19, 2021 at 9:39

1 Answer 1

5

Found the problem. Apparently I gave an undefined to a Link href, but only sometimes. So a simple check to see if the given value exists was enough in the end.

Sign up to request clarification or add additional context in comments.

1 Comment

It's this problem! You save my life! I set a process.env.URL value to <Link> and there is no error even if I use Typescript, my solution is using nullish coalescing operator(??) to make sure there is a value

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.