0

THIS IS NOT A DUPLICATE. I am asking about createBrowserHistory. The question you claim is a duplicate does NOT use createBrowserHistory.

I've found many questions about react-router and heroku but am having trouble finding ones using createBrowserRouter which is recommended in the v6 react-router docs.

Everything works fine locally but when I upload it to heroku, the app says 'Cannot GET' and whatever page it is for everything except my homepage. I tried adding a static.json but that didn't work. I also tried setting the homepage to my heroku apps url and that didn't help either. Here's the relevaant code snippets (the whole index.js is long)

index.js `

...const router = createBrowserRouter([
      {
        path: '/',
        element: <Home />,
        errorElement: <Error />,
        children: [
        ]
      },
      {
        path: 'work-history',
        element: <WorkHistory />
      },...

    ...const root = ReactDOM.createRoot(document.getElementById('root'));
    root.render(
      <React.StrictMode>
        <Provider store={store}>
          <RouterProvider router={router} />
        </Provider>
      </React.StrictMode>
    );`

static.js

`{
  "root": "build/",
  "clean_urls": false,
  "routes": {
    "/**": "index.html"
  }
}`
  • I need a response specifically about createBrowserRouter. I knew someone was going to flag this as a duplicate and IT IS NOT. I've spend hours looking for a response. There isn't one. The referenced duplicate does not have the word createBrowserRouter ANYWHERE on the page. Please reopen this so I can get an answer. I need help. – johnturner4004 Jan 06 '23 at 22:35
  • How to serve a React app hosted on Heroku has been asked and answered likely dozens of times. What router or routing/navigation library you use isn't that relevant to the issue of serving the app. The client needs to get the code first, right? If you've applied the server configurations and still have some issue then please [edit] and share what the actual issue(s) is(are) (*anything is better than "it doesn't work"*) and explain in specific detail what makes the post not a duplicate of any of the others. – Drew Reese Jan 07 '23 at 03:21
  • None of them are using createBrowserRouter. I'm asking about createBrowserRouter not serving a React app. It's very relevant because that's the preferred router in v6 of react-router so you don't have a CURRENT answer. They're all outdated. Please stop arguing and remove this as a duplicate because it's NOT. If you don't like it just move on to someone elses question. – johnturner4004 Jan 07 '23 at 04:16
  • I literally said I did what the linked "duplicate" says to do and it isn't working. – johnturner4004 Jan 07 '23 at 06:09

0 Answers0