Redirect to Angular 2 URL


#1

I’m trying to use Electron to package an app I wrote using Angular 2. With Angular 2 it generates a single index.html file and a bunch of js code that loads the various “pages”. In a browser you access a page via parameters added to the URL. So for example…

localhost:4200/

goes to my launch page and

localhost:4200/settings/

goes to a settings page

what I would like to do is make it so my Electron exe loads the settings page when it starts with a specific CLI flag. How do I load the index.html from a file, then redirect to a URL that’s relative to that?


#2

Never mind I figured it out on my own. I changed the routing method to hash and then I used url.format to load the file index.html with the hash of the page I wanted to redirect to


#3

Can you please post some tutorial on how to add electron to angular2 project done with angular/cli? I have asked a question here: http://stackoverflow.com/questions/43191473/how-to-add-electron-to-angular-project-made-with-angular-cli but noone answers


#4

I use electron-packager…

Makes the whole process much simpler.

Also when you build your angular project set the base href to ./


#5

Here are the exact configs I use from my package.json…

“build”: “ng build --prod -aot -bh ./”,
“electron”: “xcopy /Y “electron\.” “dist” && electron-packager ./dist --icon=icon.ico --out=”…\build\desktop" --platform=win32 --arch=ia32 --asar --overwrite",

I have a folder in the main angular project folder called “electron” which contains the entry.main.js file and the package.json file for electron. I also have a windows ico file I created in the main angular project folder.

I run npm run build first, then npm run electron. That generates the electron packaged file, and all it’s dependencies, in a folder one level above the angular project called “build”.