Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routing not working when running app with Production Config #1853

Closed
anupamvijayvergia opened this issue Oct 12, 2018 · 5 comments
Closed

Routing not working when running app with Production Config #1853

anupamvijayvergia opened this issue Oct 12, 2018 · 5 comments

Comments

@anupamvijayvergia
Copy link

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>
@anupamvijayvergia
Copy link
Author

I've found the issue. For anyone else facing the same problem, Replace ConnectedRouter with HashRouter in Root.js

According to react-router docs, you should HashRouter if you are using a static file server, Since after build files are served as static files and not from a server.

@vikr01
Copy link
Contributor

vikr01 commented Oct 16, 2018

ConnectedRouter should not be removed @anupamvijayvergia, that's part of the redux uses in this project.

This is less a solution and more of a workaround.

You'd need to tell your server to "handle all other routes" with the correct path. With express, you would set a route *.

@cloudstr21
Copy link

i am experiencing same issue here. @vikr01 could you please explain how to to that?

@SimantoR
Copy link

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

@hot-gril
Copy link

hot-gril commented 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants