NodeJS vite-typescript-ssr-react - No routes matched location

hs1rzwqc  于 9个月前  发布在  Node.js
关注(0)|答案(1)|浏览(87)

我是NodeJS的新手,当我像在react应用程序中一样将路由添加到app.tsx文件时,我正在使用这个模板vite-typescript-ssr-react

import React from "react";
import { Routes, Route } from "react-router-dom";

import AuthPage from "./pages/AuthPage.tsx";
import DashboardPage from "./pages/DashboardPage.tsx";
import { ContextWrapper } from "./context/Context.tsx";

export const App = () => {
  return (
    <ContextWrapper>
      <Routes>
        <Route path="/auth" element={<AuthPage />} />
        <Route path="/dashboard" element={<DashboardPage />} />
      </Routes>
    </ContextWrapper>
  );
};

export default App;

字符串
我得到以下错误:

app  | No routes matched location "/" 
app  | No routes matched location "/tailwindcss/components" 
app  | No routes matched location "/tailwindcss/utilities" 
app  | No routes matched location "/tailwindcss/base" 
app  | No routes matched location "/favicon.ico"


我不知道我在这里做错了什么……

wvmv3b1j

wvmv3b1j1#

我不知道发生了什么,但错误已经消失了。
我的意思是我确实改变了路由器,但我不知道是什么造成的差异。
这是我的新方法,首先是路由文件,

// src/client/router/routes.ts
// Define the routes and components of the application

import React, { lazy } from "react";

// Import your pages
const Home = lazy(() => import("../pages/HomePage.tsx"));
const Auth = lazy(() => import("../pages/AuthPage.tsx"));
const Dashboard = lazy(() => import("../pages/DashboardPage.tsx"));

// Define types in your route configuration object (each route should have a path and a component)
type RouteConfig = {
  path: string;
  component: React.ComponentType<any>; // Component type with any props
};

// Define your route objects
export const routes: RouteConfig[] = [
  { path: "/", component: Home },
  { path: "/auth", component: Auth },
  {
    path: "/dashboard",
    component: Dashboard,
  },
];

字符串
这是路由器:

// src/client/router/Router.tsx
// React router for the client side of the application.

import React, { lazy, Suspense } from "react";
import { Routes, Route } from "react-router-dom";
// Context
import { ContextWrapper } from "../context/Context.tsx";
// Routes
import { routes } from "./routes";
// Components
const NotFound = lazy(() => import("../pages/NotFoundPage.tsx"));

// Fall back component
const Loading = () => (
  <div className="flex justify-center items-center h-screen bg-gray-100">
    <div className="bg-white p-8 rounded shadow-md w-96 grid place-items-center">
      <p className="text-xl font-semibold mb-4">Loading...</p>
    </div>
  </div>
);

export const Router = () => {
  return (
    <ContextWrapper>
      <Suspense fallback={<Loading />}>
        <Routes>
          {routes.map(({ path, component: Component }) => (
            <Route key={path} path={path} element={<Component />} />
          ))}
          <Route path="*" element={<NotFound />} />
        </Routes>
      </Suspense>
    </ContextWrapper>
  );
};

export default Router;

相关问题