question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New experimental dynamic routing breaks zone support

See original GitHub issue

Bug report

When using experimental dynamic routes (#7432) in a zoned app. I get this error in the browser:

Your `<Link>`'s `as` value is incompatible with the `href` value. This is invalid

Describe the bug

In order to find the query parameters, href and as are matched against each other. But the current implementation seems to be too strict.

see https://github.com/zeit/next.js/blob/21fae5262f2dada7a229e6dd2831639d330ff746/packages/next-server/lib/router/router.ts#L274-L281

To Reproduce

See https://github.com/Xiphe/next-dynamic-route-in-zone

  1. Create a next app
  2. Add a proxy to have it mounted on a subpath (like http://localhost:3000/foo)
  3. Add a index page and a dynamic page (like pages/bar/$dyn.js)
  4. Try to link to the dynamic page from the index page
    <Link href="/bar/$dyn" as "/foo/bar/baz"><a>Baz</a></Link>
    
  5. Click the link in the browser

Expected behavior

I want to use dynamic routes in a zoned app, so the above Link-code should not throw.

System information

  • OS: macOS
  • Browser: chrome
  • Version of Next.js: 8.1.1-canary.43

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:11
  • Comments:24 (11 by maintainers)

github_iconTop GitHub Comments

7reactions
sventschuicommented, Nov 7, 2019

If you do not want to incorporate the zone name into your pages directory then you can use the following monkey patch to work around this issue (Note: I store the zone/base path in the next public runtime config but you can hardcode it):

import getConfig from 'next/config';
import * as routeMatcher from 'next/dist/next-server/lib/router/utils/route-matcher';

const { publicRuntimeConfig } = getConfig();

if (!routeMatcher._patched) {
  routeMatcher._patched = true;
  routeMatcher._getRouteMatcher = routeMatcher.getRouteMatcher;
  routeMatcher.getRouteMatcher = function getPatchedRouteMatcher(routeRegex) {
    const originalMatcher = routeMatcher._getRouteMatcher(routeRegex);

    return function patchedRouteMatcher(route) {
      if (route.indexOf(publicRuntimeConfig.basePath) === 0) {
        route = route.substr(publicRuntimeConfig.basePath.length);
      }

      return originalMatcher(route);
    }
  }
}
5reactions
isaachinmancommented, Aug 21, 2019

I’m glad that @Xiphe came to a conclusion for their personal project, but downstream dependencies like next-i18next need to be able to insert subpaths without making modifications to the filesystem.

See https://github.com/isaachinman/next-i18next/issues/413.

Can we reopen this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic routing with Cloud Router | Google Cloud - Community
On Google Cloud, dynamic routing can be established using Cloud Router. It exchanges network topology information through Border Gateway ...
Read more >
Dynamic Routing - an overview | ScienceDirect Topics
The dynamic routing algorithm is the algorithm that produces the outputs. This is done both during training and during testing, given the values...
Read more >
What's new in Angular 14? - Ninja Squad
Route providers, standalone routes, loadComponent. A bunch of new things have been added to the router to support the new standalone APIs. For ......
Read more >
Dynamic Vehicle Routing Problem—Predictive and ... - MDPI
The authors consider the breakdown of vehicles and the need to create a new schedule by minimizing transportation costs and deviations from the...
Read more >
Advanced Features: Next.js Compiler
v12.2.0, SWC Plugins experimental support added. ... __generated__ directory, and this file will be considered a route, which will break production builds.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found