-
Notifications
You must be signed in to change notification settings - Fork 26k
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
/basePath redirects to root in NextJS 13 (appDir) #41824
Comments
I can confirm, this is also stopping me from deploying my nextjs13 project. It also breaks next/image, but I found the following workaround for that in another thread.
|
Can confirm also. The workaround we've come up with makes use of the redirects functionality in the config.
Of course this is increases loading time with the added redirect. |
Can also confirm this is still happening for me. Sadly the workaround above didn't solve my case, as the path still is not rewritten to the base path on redirect. I'll add that you can see that |
still happening |
I deployed my project to production with this issue, here's what I've learned. It covers a case where you have another page at root, and how to deal with it in nginx. Since I have multiple subpages, including dynamic routes directly under root I had to add a whole set of rules following @alexdgourlay's instructions. Keep in mind that you can use regex, in my case this was required to separate the dynamic routes. This worked in dev, however in prod I had to give up on this idea and instead created a new subfolder above the dynamic route, so it doesn't site directly under root.
Here's what it looks like in my example, my basepath would be
However, in production I have another site at root (the reason I'm using a base path), and unlike dev, (this is my understanding), because the browser goes to root for a split second before the redirect can kick in, my nginx for the site at root is in control and the redirect can't resolve. The solution for this was to add more rules for nginx. These need to be uniquely identifiable, so that nginx knows they came from the nextjs app and can send you back there.
At this point I decided to give up on The next problem is that you can't link back to
everywhere I have a link to
If use the broken redirect from within the app, the base path is swallowed as we know, and it goes to Because I handle it through nginx now, all of the nextjs/next.config.js redirects except those for home could be removed. However, this won't work in dev, so I'll personally be keeping them. Bottom line, things get worse in production when you actually have something at root. You need lots of redirects which makes links ugly and the performance slow. And if you change something you have to look in lots of places. I'm sure there are better ways to do this, and that nginx has advanced functions to deal with this. I know it's Christmas and everyone deserves their time off. Images with basepath were fixed, and I hope routes/links are next. Thanks devs! |
This bug holding back my app upgrade. :/ |
This issue went away after my upgrade to 13.1.1. 🎉 |
It still not working properly on 13.1.2 canary. // next.config.js
module.exports = {
basePath: '/docs',
experimental: { appDir: true },
} export default function HomePage() {
return (
<Link href="/style-guide">Style Guide</Link>
)
} when hovering, the browser shows the correct url According to the documentation, the expected url should be
|
Resolved for us upon updating to v13.1.1 😄 |
I created issue #44893 to add a codesandbox example for the latest canary release. I don't know how you guys solved it, it's still happening for me (and in the code sandbox). |
Nevermind, I'm still having the issue but it's router related? |
Also in NextJS 13.1.5 the issue still seems to exist. |
Have successfully resolved this. As is usual it's all about slashes! Make sure your basepath in next.config.js begins with a slash and doesn't have one on the end:
and your nginx config does NOT end in a slash:
|
it's nice when you can use redirects, but if you have to use a hosting solution where you're deploying under a basepath, and you have no permission to redirect (especially from the root), then this doesn't work. That's why it's just a work around and nextjs should have a selfcontained solution. |
Closes #41824. ## Bug - [ ] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm build && pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
I can confirm that the issue is resolved in v13.1.7-canary.9. Didn't test canary.10 yet. |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 21.6.0: Mon Aug 22 20:19:52 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T6000
Binaries:
Node: 16.14.0
npm: 8.3.1
Yarn: 1.22.18
pnpm: N/A
Relevant packages:
next: 13.0.0
eslint-config-next: 13.0.0
react: 18.2.0
react-dom: 18.2.0
What browser are you using? (if relevant)
Firefox 106.0.1
How are you deploying your application? (if relevant)
No response
Describe the Bug
In NextJS 13, the document at
/myapp
instantly redirects to the root path/
.During this redirect, or
replaceState
, the/myapp
entry is not registered in history.While the root
app/layout.tsx
andapp/page.tsx
is now rendered on screen, the website becomes a404
if we reload the location/
without the/myapp
segment.It would appear that
basePath
works differently or not at all in version 13 👀Expected Behavior
The
/{basePath}
should stick around in the location so that we can reload forever.Link to reproduction
https://github.com/wiredearp/basepath-redirect
To Reproduce
Create a website with
create-next-app
, setbasePath
and enableappDir
. Thenrun dev
and visit the/{basePath}
to witness the redirect. This setup can be cloned from the reproduction repo. Thanks for digging in!The text was updated successfully, but these errors were encountered: