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

Electron reload not working #15

Closed
p3140 opened this issue May 9, 2017 · 13 comments
Closed

Electron reload not working #15

p3140 opened this issue May 9, 2017 · 13 comments

Comments

@p3140
Copy link

p3140 commented May 9, 2017

Hi. First of all thanks for this great repository. Im pretty new working with Angular 4 so this problem may be because of that.
The issue is that live reloading my app after changes in the code are done is not possible until i change app-routing.module.ts to this:

@NgModule({
    imports: [RouterModule.forRoot(routes, {useHash: true})],
    exports: [RouterModule]
})

Also i had to change index.html base href tag to be empty:
<base href="">
all this to tell angular to work with hashbang style routes instead of html5 style routes.

The solution came from here.

¿is this the right solution or i'm missing something?

Thanks in advance, gr33ts from Chile.

maximegris added a commit that referenced this issue May 10, 2017
@maximegris
Copy link
Owner

Thanks for this report !
I pushed the fix.

Regards

maximegris added a commit that referenced this issue May 10, 2017
@michaelb-01
Copy link

I think I’m having the same issue, is this the only solution? It would be nice to be able to configure electron to work with html5 location strategy (angular’s default)

@shivarajnaidu
Copy link

Yes... Is there any other solution for this to make things work with angular's default strategy

@jddeltoro
Copy link

Had the same issue working with electron & angular 7, this solved for me.

@Shaimae18
Copy link

2019 still working dude
Ng8

@CPrescher
Copy link

The change to <base href=''> actually breaks reloading right now for routing without useHash=true.

It adds to every URL an extra backslash which cannot be resolved by the router e.g. it goes from "file" to "file/" which is quite annoying and it is hard to find out why this is happening.

I checked with electron and the reload seems to work for hashing and without it with the
<base href='/'> at least for angular 9

Since the latest version of this repo is supporting angular 9, would it be possible to change the base element back, since there is no need for the href='' anymore and it only will provide confusion for future users who also do not want to use hashing.

@maximegris
Copy link
Owner

maximegris commented Apr 20, 2020

@CPrescher You are right. The base-href should be declared with / in order to use both routing strategies (with or without fragments) with hot reload.

By the way routing doesn't seems to work when the app is encapsulate in an electron executable when base-href is set to / (after running electron:local or electron:linux or electron:windows or electron:mac).

To make it works, I had to set --base-href ./ in npm build script.

I also added another page module to check that the routing is correctly working.

@CPrescher
Copy link

Great, thank you for making this change so fast.

@maximegris
Copy link
Owner

You're welcome :)

@seiyria
Copy link

seiyria commented May 13, 2020

Is webpack supposed to reload the renderer when you change angular-related code? I'm not seeing webpack attempt to recompile anything when I change an html file.

@petef19
Copy link

petef19 commented Jun 17, 2020

Also cannot get this to work. my stack:

@ionic/[email protected]
@ionic-native/[email protected]
@capacitor/[email protected]
[email protected]
[email protected]

Had to employ the {useHash: true} option as well as set to get manual reload working via ctrl+R. electron-reload itself never works on this stack.

If I add it top of Electron's index.js file (Capacitor renamed main.js to index.js) as per the example on the main page of this repo, then on every detected change the cursor starts flickering and an endless spinning circle appears next to the cursor until I close the Electron window...

any idea how to fix this ? would love to have auto-reloads in Electron browser...

@mariotaku
Copy link

For people who still have this issue, do a force app load if failed:

win.webContents.on('did-fail-load', () => win.loadURL(...));

@rbalet
Copy link

rbalet commented Jun 25, 2021

For people who still have this issue, do a force app load if failed:

win.webContents.on('did-fail-load', () => win.loadURL(...));

This will work, but you will loose the value of the variable because your app will be restarting. So if you need a log-in screen before you're able to run the electron app, be sure to store the value in the localStorage or somewhere else

@maximegris
Adding the --base-href ./ make my app loose the location to the assets folder. did you had the same problem ? If yes could you find a fix?

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

No branches or pull requests