admin管理员组

文章数量:1387455

Sure I'm doing something silly here.... I have a webapp using react-router-dom (v6.21.1):

const router = createBrowserRouter([
    {
        path: "/",
        element: <Home />,
        errorElement: <NotFound />
    },
    {
        path: "/page1",
        element: <Page1 />,
    },
    {
        path: "/page2",
        element: <Page2 />,
    }
]);

ReactDOM.createRoot(document.getElementById("root")).render(
    <React.StrictMode>
        <RouterProvider router={router} />
    </React.StrictMode>
);

serviceWorker.unregister();

In production, if I navigate to my root location ("www.mysite/") then navigate into any of the children routes ("/page1" and "/page2") everything works fine. If I open up a new tab and navigate to a child route, works great. If I go to a brand new browser and try to navigate directly to a child link, I get <NotFound />.

I'm sure I'm just missing something, but I'm struggling to test and/or find any information about this because the minute I navigate to "/", the router works for that browser.

本文标签: nodejsRouting using createBrowserRouter only resolves children routes when starting at rootStack Overflow