question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Routing not working when running app with Production Config

See original GitHub issue

Opening a new window with specifc page is redirecting back to index route. This behavior is only happening when running the application with npm run start. Routes are working properly when running the application with num run dev .

childWindow.loadURL(`file://${__dirname}/app.html#/${containerId}/second`);

Routes are setup as below.

<App>
    <Switch>
      <Route path="/signup" component={SignUpContainer} />
      <Route path="/home" component={HomeContainer} />
      <Route path="/:containerId/second" component={SecondContainer} />
      <Route path="/" component={SplashContainer} />
    </Switch>
  </App>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
SimantoRcommented, Jan 21, 2020

My understanding was the same regarding HashRouter. This is my entrypoint code

ReactDOM.render(
    <HashRouter basename="/">
        <App />
    </HashRouter>,
    rootElement
);

And this is my Switch-Route setup

<Switch>
    <Route exact path="/">
        <Landing dbManager={dbManager} printer={printer} />
    </Route>
    <Route path="/settings">
        <Settings dbManager={dbManager} printer={printer} />
    </Route>
    {/* No Path */}
    <Route>
        <p>
            Sorry go back to {' '}<NavLink to='/'>home page</NavLink>
        </p>
    </Route>
</Switch>

Warning I get:

Warning: Hash history cannot PUSH the same path; a new entry will not be added to the history stack
0reactions
hot-grilcommented, Aug 16, 2020

Nothing worked. I looked at like 10 different answers for this. Eventually figured this out through trial and error, works in both dev and prod:

win.loadURL(`file://${electron.remote.app.getAppPath()}/app.html#/yourroutename`)

__dirname works only in dev.

I wrote an SO answer with more details: https://stackoverflow.com/a/63441289/1884363

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular routing not working after running ng build at deployment
I'm running Angular 12.2. 0 and have setup routes on localhost. I'm just navigating between two pages at the moment to see how...
Read more >
Handling React Routing in Production - Pluralsight
This guide shows how to solve a page not found error you've in a React app that uses React Router or the HTML5...
Read more >
Router tutorial: tour of heroes - Angular
In this tutorial, you build upon a basic router configuration to explore features such as child routes, route parameters, lazy load NgModules, guard...
Read more >
Deployment | Create React App
npm run build creates a build directory with a production build of ... This may not work for client-side routers which expect the...
Read more >
Set up staging environments - Azure App Service
Learn how to deploy apps to a non-production slot and autoswap into ... Some configuration elements follow the content across a swap (not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found