Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
How to make shallow routing work on nested next js routes?

I'm trying to recreate the instagram shallow routing logic, which looks like this:

  1. user is on the instagram.com/p/cristiano.
  2. clicks on one of the pictures.
  3. url changes to instagram.com/p/Cd0..., instead of being taken to detail page, user is presented with modal
  4. on modal exit url changes back to instagram.com/p/cristiano.

enter image description here

Here is how I'm trying to recreate this logic:

shallowRoutingOrigin is the page from where I am opening the modal: could be either savedworkouts,discovery or u/${username}

  const handleShallowRoutingClick = (documentId: string) => {
    router.push(
      `/${shallowRoutingOrigin}?documentId=${documentId}`,
      `workoutpreview/${documentId}`,
      {
        shallow: true,
      }
    );
    setModalIsOpen(true);
  };

  const handleModalClose = () => {
    router.push(`/${shallowRoutingOrigin}`, undefined, {
      shallow: true,
    });
    setModalIsOpen(false);
  };

The following logic and desired effect works on savedworkouts and discovery pages, however when I try to open the modal from u/${username}, instead of masking. url as /workoutpreview/id1 it masks as /u/workoutpreview/id1 and I get 404 this page not found error.

What makes this logic not work on the user page?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!