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

Equivalent to createURLRoute in new version? #21

Open
sebbean opened this issue Sep 16, 2024 · 8 comments
Open

Equivalent to createURLRoute in new version? #21

sebbean opened this issue Sep 16, 2024 · 8 comments

Comments

@sebbean
Copy link

sebbean commented Sep 16, 2024

i've installed in a project with electron-vite and react

everything seems to be ok except

I can't seem to match the homepage in dev mode
<Router basename="/main"> is not able to match the URL "/" because it does not start with the basename, so the <Router> won't render anything.

Seems to be related to the lack of ability to load a url vs a htmlFile:

  registerRoute({
    id: 'main',
    browserWindow: mainWindow,
    htmlFile: join(__dirname, '../renderer/index.html'),
  })
  // HMR for renderer base on electron-vite cli.
  // Load the remote URL for development or the local html file for production.
  if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
    mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])

  } else {
    // mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
  }
@sebbean
Copy link
Author

sebbean commented Sep 16, 2024

ok figured it out

had to registerRoute at the end

and then find the vite port and paste into the config

image

@sebbean
Copy link
Author

sebbean commented Sep 16, 2024

figured it out!

@sebbean sebbean closed this as completed Sep 16, 2024
@sebbean sebbean reopened this Sep 16, 2024
@sebbean
Copy link
Author

sebbean commented Sep 16, 2024

not quite - i'm noticing HMR is not working

seems to be using the index.html file and not the local dev server

@sebbean
Copy link
Author

sebbean commented Sep 16, 2024

this is the bottom of my createWindow function


  // HMR for renderer base on electron-vite cli.
  // Load the remote URL for development or the local html file for production.
  if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
    mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])

  } else {
    mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
  }

  registerRoute({
    id: 'main',
    browserWindow: mainWindow,
    htmlFile: join(__dirname, '../renderer/index.html'),
  })

and things load but no hot module reloading

@sebbean
Copy link
Author

sebbean commented Sep 16, 2024

ok turns out HMR works in the top level App / Layout files

But not for the individual route content itself (most of the app)

i know its a recent version! hope this is helpful

ty

@daltonmenezes
Copy link
Owner

Hi @sebbean , you no longer need to do this manually:

  if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
    mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])

  } else {
    mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
  }

registerRoute handles this logic internally, in the development environment it will be used loadURL, in production loadFile as you can see here:

https://github.com/daltonmenezes/electron-router-dom/blob/main/packages/electron-router-dom/src/index.ts#L104-L121

@daltonmenezes
Copy link
Owner

daltonmenezes commented Sep 16, 2024

@sebbean Also, could you please test/check the with-multiple-windows example?

@sebbean
Copy link
Author

sebbean commented Sep 16, 2024

@daltonmenezes it does look like this is actually an issue with vite + react-dom-router not triggering page content refreshes

i see the reload happen on both the server terminal as well as the dev console in the app

the content inside the page content stays stale

but content in the wrapper layout changes (HMRs) fine

thanks again!

i'll check out

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

2 participants