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

URL will back to home when use Dynamic Routes and SSG and deploy with nginx #26764

Closed
aimer-fan opened this issue Apr 13, 2024 · 2 comments
Closed

Comments

@aimer-fan
Copy link
Contributor

Environment

  • Operating System: Darwin
  • Node Version: v20.10.0
  • Nuxt Version: 3.11.2
  • CLI Version: 3.11.1
  • Nitro Version: 2.9.6
  • Package Manager: [email protected]
  • Builder: -
  • User Config: devtools
  • Runtime Modules: -
  • Build Modules: -

Reproduction

  1. use pnpm dlx nuxi@latest init <project-name> create a project
  2. add pages/[..slugs].vue
<template><div>Nuxt App</div></template>
  1. run pnpm run generate command and move to dist folder to nginx root folder
  2. set nginx.conf
location / {
  try_files $uri $uri/ @router;
  index  index.html index.htm;
}

location @router {
  rewrite ^.*$ /index.html last;
}
  1. visit /foo, browser will back to / path when nuxt app is ready

Describe the bug

when you visit /foo, nginx will return the index.html, but the url will back to the / after nuxt app ready.

I found that initialURL will be override by nuxtApp.payload.path.

: createCurrentLocation(routerBase, window.location, nuxtApp.payload.path)

so i add useNuxtApp().payload.path = '' to app.vue, it works.

Is there any other better way to solve this problem?

Additional context

No response

Logs

No response

@NamesMT
Copy link

NamesMT commented Jul 22, 2024

Bump, encountering this as an major issue in our upcoming internal app, there are dynamic routes that are sent by email and could not be accessed.

@danielroe
Copy link
Member

The best solution here is to have nginx serve up 200.html for unknown routes that have not been prerendered. (It's intended for that purpose.)

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants