Description
Discussed in #12891
Originally posted by batchor January 29, 2025
My situation is a little bit complicated and I will try my best to tell a clear story.
Simple description
The content of the statically generated index page is showing up on every dynamic client-side rendered route.
Please visit https://debug.batchfy.com and https://debug.batchfy.com/a/b to checkout the behaviours.
Detailed story
I have a dynamic route, e.g., '/:user/:project', and all other pages, including the index page, are statically generated during building for SEO purposes.
My react-router.config.ts
:
import type { Config } from "@react-router/dev/config";
export default {
ssr: false,
async prerender() {
return ["/", "/about"];
},
} satisfies Config;
and my app/routes.ts
:
import { type RouteConfig, index, route, layout } from "@react-router/dev/routes";
export default [
index("routes/home.tsx"),
route("about", "routes/about.tsx"),
route(":username/:projectname", "routes/project.tsx"),
] satisfies RouteConfig;
In my app/routes/home.tsx
, I simply have:
import type { Route } from "./+types/home";
import { Welcome } from "../welcome/welcome";
export function meta({}: Route.MetaArgs) {
return [
{ title: "ScienHub" },
{ name: "description", content: "LaTeX" },
];
}
export default function Home() {
return <h1>homepage</h1>;
}
And my app/routes/project.tsx
displays the route parameters:
import type { Route } from "./+types/project"
export default function Project({
params,
}: Route.ComponentProps) {
return <h1 className="text-red">{params.username}/{params.projectname}</h1>
}
The nginx.conf
:
server {
listen 51580;
server_name example.com;
root /my-react-router-app/build/client;
try_files $uri $uri/index.html /index.html;
}
Expected behavior
When I visit example.com
, I can see "Homepage" on the screen.
And when I visit example.com/user1/project2
, I see "user1/project2".
Actually behavior:
When I visit example.com/user1/project1
, the actual result is:
"
Homepage
user1/project1
"
The content of the statically generated index page, "Homepage", shows up on every dynamical route.
Other information
npm run dev
works perfectly fine; the issue arises only with the static build when deployed behind Nginx.