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.

Allow Incompatible HREF and AS values

See original GitHub issue

Feature request

Is your feature request related to a problem? Please describe.

To allow for advanced usage of routing we currently have the capability to use Link and router.push/replace with unmatched/incompatible href and as values. For example, we are able to do the following:

Router.push(`/user?photoId=${id}`, `/user/photo?id=${id}`)

This allows developers to implement advanced routing UX such as instagram style modals, where a modal can open on the same page but also have a dedicated page.

The current challenge is that when a dynamic element is added to the values an error is emitted noting incompatible href and as values - https://github.com/zeit/next.js/blob/master/errors/incompatible-href-as.md For example:

Router.push(`/[user]?photoId=${id}`, `/user/photo?id=${id}`)

Describe the solution you’d like

The reason this error is produced is due to the following section of code, which checks both values match: https://github.com/zeit/next.js/blob/69b7538dce2fa8853bccfa2f65c8c305d76daae3/packages/next/next-server/lib/router/router.ts#L319

On removing this check all routing functions as expected (including the dynamic route) and all tests still pass. For this reason I would like to request that this section of code is reviewed and potentially removed.

Describe alternatives you’ve considered

An alternative solution is to allow a flag that disables this route match check, potentially reducing features for this situation and/or allowing for an at risk implementation (if there is a risk introduced when removing this route match check)

Additional context

I have forked an instagram clone, updating the next package to the latest version and introduced a dynamic route. When disabling the section of code noted above all routing functionality works as expected: https://github.com/tomevans18/nextagram

I have also forked next.js and commented out the section of code noted above. When running the tests against this repo, all routing tests pass: https://github.com/tomevans18/next.js

If there is any additional investigation work that needs to be done to help this feature happen please let me know and I will be happy to oblige.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:10
  • Comments:15 (10 by maintainers)

github_iconTop GitHub Comments

7reactions
Timercommented, Jan 20, 2020

Supported in ^9.2.1-canary.6. Please give it a try!

2reactions
philgruneichcommented, Feb 14, 2020

Fixed by changing the structure of the link to:

<Link href={`/project/post?id=${id}`} as={`${PREFIX}/project/post/${id}`} passHref>
  <Button>Example</Button>
</Link>
Read more comments on GitHub >

github_iconTop Results From Across the Web

The provided `as` value is incompatible with the `href` value ...
Error: The provided as value (/home/settings/subscription) is incompatible with the href value (/[type]). I am not using as anywhere.Can someone ...
Read more >
Dealing with links in Next.js - LogRocket Blog
My first technique is wrapping the Link component. Every routing library has a similar component; it is used instead of the <a> tag....
Read more >
Dynamic Link - Appian 22.4
One or more variables that are updated with the link's value when the user clicks it. Use a!save(target, ... Sync-Time Custom Record Fields,...
Read more >
Routing In Canjs Not Working As Links Are Not Getting An Href Value
To allow for advanced usage of routing we currently have the capability to use Link and router.push/replace with unmatched/incompatible href.
Read more >
Next.js: errors/incompatible-href-as.md - Fossies
Somewhere you are utilizing the next/link component, Router#push , or Router#replace with a dynamic route in your href that has an incompatible as...
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