'NextJS shallow routing will recreate _app.js

I want to sync url with filters that user applied in my nextjs application.

I tried this code:

router.replace(
  {
    search: stringify({ ...queryFromUrl, ...newQuery }, mergedStringifyOptions) || '?',
  },
  undefined,
  { shallow: true },
);

but this will recreate _app.js

If I remove shallow: true this will call getStaticProps again.

The problem I think is because filters does not exists in url at first. But How can I fix this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source