Migrating from v1 to v2
Learn how to migrate from Electron Router DOM v1 to v2
Updating dependencies
Remember, the minimum versions required for Electron Router DOM v2
are:
- electron:
>=17.0
- react:
>=18.0
- react-router-dom:
>=6.22.3
Creating the electron-router-dom.ts
file
In the src
folder of your project, create a lib
folder and inside it the electron-router-dom.ts
file.
It is through this new file that you will expose the registerRoute
method and the Router
component to your application.
- The registerRoute method will be used in the
main process
to register a window as a route of the application. - The Router component will be used in the
renderer process
to navigate between the windows/routes of the application.
Updating the main process
With the removal of the createFileRoute
and createURLRoute
functions from the electron-router-dom
package, the process has become simpler and more intuitive.
Now, you only need to import the registerRoute
function from the electron-router-dom.ts
file you created earlier.
What was done this way before:
Now, it will be done like this:
You no longer need to worry about the logic of loading the development server URL or the application HTML file, Electron Router DOM
will take care of it for you.
Updating imports in the rendering process
Now the Route
component is no longer exported from the electron-router-dom
package, but from the react-router-dom
package.
In addition to simplifying the use of Electron Router DOM
, this decision will help cause less confusion about what should be imported from each package.
š You are now ready to use Electron Router DOM v2
To get the most out of the library, we recommend you to read the rest of the documentation or look at the existing examples!