skip to Main Content

I write a simple app in react and in this app i use the createBrowserRouter component:

import React from "react";
import { createRoot } from "react-dom/client";
import App from "./App";
import reportWebVitals from "./reportWebVitals";
import { ThirdwebProvider } from "@thirdweb-dev/react";
import { Sepolia } from "@thirdweb-dev/chains";
import "./styles/globals.css";
import "bootstrap/dist/css/bootstrap.min.css";
import { createBrowserRouter, RouterProvider } from "react-router-dom";
import ErrorPage from "./error-page";
import xxx from "./routers/xxx";

const router = createBrowserRouter([
  { path: "/", element: <App />, errorElement: <ErrorPage /> },
  { path: "xxx", element: <xxx /> },
  { path: "xxx/:xxx", element: <xxx /> },
  { path: "xxx/:xxx/:xxx/", element: <xxx /> },
  { path: "xxx/:xxx/:xxx/:xxx", element: <xxx /> },
  { path: "xxx/:xxx", element: <xxx /> },
]);

const container = document.getElementById("root");
const root = createRoot(container!);
root.render(
  <React.StrictMode>
    <ThirdwebProvider
      activeChain={Sepolia}
      autoConnect={true}
    >
      <RouterProvider router={router} />
    </ThirdwebProvider>
  </React.StrictMode>
);

reportWebVitals(console.log);

When I deploy to the IPFS network they get me a link with a path like: "https://ipfs.thirdwebcdn.com/ipfs/hashOfBuildFolder"

According to the doc they say to do in this way

const router = createBrowserRouter([
  { path: "/", element: <App />, errorElement: <ErrorPage /> },
  { path: "xxx", element: <xxx /> },
  { path: "xxx/:xxx", element: <xxx /> },
  { path: "xxx/:xxx/:xxx/", element: <xxx /> },
  { path: "xxx/:xxx/:xxx/:xxx", element: <xxx /> },
  { path: "xxx/:xxx", element: <xxx /> },
], {
 basename:"/relative/path/"
});

but in this case is the hash of the build folder and every time I change the value of basename the hash change so the link change.

2

Answers


  1. Chosen as BEST ANSWER

    I switch to createHashRouter so now i have no more the issue. This is just a way to not have the problem not the solution.


  2. basename:"/relative/path/" i think there should not be trailing slash here and you should add slash in each route, example
    basename should be: basename:"/relative/path"
    and in rest of objects path should be { path: "/xxx",

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search