Vite React SSR with React Router: Facing routing related issues while implementing SSR

I have followed the guide to setup vite-react-ssr in streaming version (https://vitejs.dev/guide/ssr#example-projects). Setup everything as described in the guide and tried to setup the react router in my existing project.

Everything works fine I created routes and provide to client and server. Visiting other routes using the Link (react-router) works good without any error but doesn’t provide any html document.

When I tried to hit the route directly (/about) it returns the html document with just root and the error on the client “Hydration failed because the initial UI does not match what was rendered on the server“. And in the console I got the error no matching routes “about”.

I already read the documentation provided (reactrouter.com/en/v6.3.0/guides/ssr). I read the blog on the medium and dev.to neither was helpful, they are using renderToString method https://github.com/reactwg/react-18/discussions/22 this discussion form was all about renderToPipeableStream which is provided by the vite in the project.

I tried asking this question on react reddit community (https://www.reddit.com/r/reactjs/) haven’t received any answers from the community, I also tried the discord community (https://discord.gg/reactiflux) no one is answering.

I dont know whether my way of asking the question is right or wrong, there are frameworks that provide the SSR/SSG out of the box. But I really want to try it with react and learn the things to serve static and dynamic content alongwith SEO using react on the client.

If you feel like i’m stupid and haven’t followed something that I needed to in that case also provide me the required help. I have already gone through multiple videos and blogs.

Github Repo Link: (https://github.com/mausam-giri/vite-static-ssr-stackoverflow)

Here’s the file structure generated by vite and routes.tsx, About.tsx added by me:

// routes.tsx

const App = React.lazy(() => import("./App"));
const About = React.lazy(() => import("./About"));

export const ROUTES = [
  {
    path: "/",
    element: <App />,
  },
  {
    path: "/about",
    element: (
      <Suspense>
        <About />
      </Suspense>
    ),
  },
  {
    path: "*",
    element: <p>Path not resolved</p>,
  },
];

export default function AppRoutes() {
  return (
    <Routes>
      {ROUTES.map(({ path, element }) => (
        <Route key={path} path={path} element={element} />
      ))}
    </Routes>
  );
}

// entry-client.tsx

import AppRoutes from "./routes";

ReactDOM.hydrateRoot(
  document.getElementById("root") as HTMLElement,
  <BrowserRouter>
    <AppRoutes />
  </BrowserRouter>
);

// entry-server.tsx

import AppRoutes from "./routes";

export function render(_url: string, _ssrManifest?: string,
  options?: RenderToPipeableStreamOptions
) {
  return renderToPipeableStream(
    <StaticRouter location={_url}>
      <AppRoutes />
    </StaticRouter>,
    options
  );
}

Please help me with this, if you can provide my blog and suggest me where to learn which book to read to implement the industry level stuffs using react. I want to level up my self.

Error Screenshot:

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật