Open vicenteroa opened 2 weeks ago
Hi @alex8088
Thank you for the documentation you provided. I used it as a guide and decided to find an alternative solution for svelte-routing
by using svelte-spa-router
to handle hash routes. With this approach, the routes now work perfectly in production.
Additionally, I didn’t need to modify the main/index.js file with the { hash: '...' } option as mentioned in the documentation for other routers.
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])
} else {
mainWindow.loadFile(path.join(__dirname, '../renderer/index.html'))
}
}
Here’s the code I used:
<script>
import Router , { location , link } from 'svelte-spa-router';
import Home from './Pages/Home/home.svelte';
import Dashboard from './Pages/Dashboard.svelte';
</script>
<nav>
<a href="/">Home</a>
<a href="#/dashboard">Dashboard</a>
</nav>
<Router routes={{
'/': Home,
'/dashboard': Dashboard
}} />
<hr>
/#{$location}
It might be worth considering adding this to the documentation to help other developers who are using Svelte in a similar setup.
Thanks again for your help, and I hope this can assist others!
Best regards!
Describe the bug
Hello,
I’m experiencing an issue with my Electron app using svelte-routing and electron-vite. The routes work perfectly in development mode (npm run dev), but they do not work in production mode (npm run build and npm start). The navigation links are displayed, but the pages do not render correctly.
Steps to Reproduce:
Expected Behavior:
The routes should work in production mode as they do in development mode.
Actual Behavior:
The navigation links are displayed, but the pages do not render correctly in production mode.
App.svelte
Evidence (npm run dev)
Evidence (build - npm start)
Additional Context:
I’ve tried several configurations and ensured there are no errors in the console. The issue persists only in production mode. Any help would be greatly appreciated!
Used Scaffolding
create-electron
Used Package Manager
npm
Validations