Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error occurred when using dynamic routing and Rewrite together #26074

Closed
shu1007 opened this issue Jun 14, 2021 · 9 comments
Closed

Error occurred when using dynamic routing and Rewrite together #26074

shu1007 opened this issue Jun 14, 2021 · 9 comments
Labels
bug Issue was opened via the bug report template.

Comments

@shu1007
Copy link

shu1007 commented Jun 14, 2021

What version of Next.js are you using?

10.2.3

What version of Node.js are you using?

14.16.1

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

next start

Describe the Bug

I'm using rewrites to access a page with dynamic routing, using the Link component.
It is possible to go to the target page with a click. However, when I go back or forward in the browser, an following error occurs.
This error does not occur until 10.2.0, and is seen in 10.2.1 and later versions.

Error: The provided `as` value (/foo) is incompatible with the `href` value (/[slag1]/[slag2]/foo).

Expected Behavior

?

To Reproduce

I wrote the following sample code in code sandbox.
Please try the following steps for each.

  1. Click on Foo
  2. Go back in the browser
  3. Go forward in the browser
@shu1007 shu1007 added the bug Issue was opened via the bug report template. label Jun 14, 2021
@myteax
Copy link

myteax commented Jun 14, 2021

I will like to work on this.

@myteax
Copy link

myteax commented Jun 14, 2021

This is what I did to solve the error:

https://1bxb9.sse.codesandbox.io/

@shu1007
Copy link
Author

shu1007 commented Jun 14, 2021

Thanks for the quick response!

The point is to rewrite the url, we want to have access with /foo.
And the structure of pages remains unchanged.

@myteax
Copy link

myteax commented Jun 14, 2021

ok, I get you, I really do not understand your project 100% and why you have those dynamic paths [folder]. What I did now was to take out the foo.js and put in the page folder and then it works. Again, this might not be what you want to achieve as I really do not have more information about the project. Another way to do that is :
import Link from "next/link";

export default function IndexPage() {
return (



Foo


);
}

That will disable the backward and forward button. Then you can add a button to go back; which will lead directly to the home page.

@shu1007
Copy link
Author

shu1007 commented Jun 14, 2021

Thank you.
Talking about my project a bit, I want to provide multiple services from a common code. One service will have branches with dynamic routing and another service will not have those branches.
The actual code is much larger and more complex, and rewrite was helpful in building them with minimal changes. However, when I upgraded the next version, it stopped working, so I wrote an issue.

@ijjk
Copy link
Member

ijjk commented Jun 14, 2021

Closing as this is fixed in v10.2.4-canary.2 of Next.js, specifically in #25666 and #25495

@ijjk ijjk closed this as completed Jun 14, 2021
@PsyGik
Copy link

PsyGik commented Jun 23, 2021

Will this fix land in Next 11 or a minor version of 10?

@shu1007
Copy link
Author

shu1007 commented Jun 23, 2021

It's working correctly in Next 11

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

5 participants