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

renderer: setup react-router and two routes #30

Merged
merged 1 commit into from Jun 2, 2022
Merged

Conversation

bajtos
Copy link
Member

@bajtos bajtos commented Jun 1, 2022

Create two screens: Station Shell and Saturn Module.

Connect to #18


Initial screen:

Screenshot 2022-06-01 at 09 07 53

Saturn screen:

Screenshot 2022-06-01 at 09 07 57

@bajtos bajtos force-pushed the renderer--router branch 2 times, most recently from 74aa071 to 2de1610 Compare June 1, 2022 07:12
@bajtos bajtos changed the title Setup react-router and two routes renderer: setup react-router and two routes Jun 1, 2022
Create two screens: Station Shell and Saturn Module.

Signed-off-by: Miroslav Bajtoš <saturn@bajtos.net>
@@ -29,7 +27,7 @@ module.exports = async function (ctx) {
let devServer

if (app.isPackaged || process.env.NODE_ENV !== 'development') {
ui.loadURL(pathToFileURL(path.join(__dirname, '../renderer/dist/index.html')).toString())
ctx.loadWebUIFromDist(ui)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bajtos - what is the advantage of moving this into the context in index.js and using electron-serve?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A great question!

When serving the UI from a file:// URL, routing does not work. I tried to switch to Hash based routing too (index.html#/somepath), but it didn't work either.

With electron-serve, we register a custom scheme app: and load the UI via "proper" URL app://-/.

See also https://www.npmjs.com/package/electron-serve:

Normally you would just use win.loadURL('file://…'), but that doesn't work when you're making a single-page web app, which most Electron apps are today, as history.pushState()'ed URLs don't exist on disk. It serves files if they exist, and falls back to index.html if not, which means you can use router modules like react-router, vue-router, etc.

@bajtos bajtos merged commit 57e58aa into main Jun 2, 2022
@bajtos bajtos deleted the renderer--router branch June 2, 2022 05:55
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

Successfully merging this pull request may close these issues.

None yet

2 participants