$ show daltonmenezes/electron-router-dom
Electron Router DOM is a library that facilitates the integration of react-router-dom with Electron applications, enabling window-based routing where each Electron window can have its own routing configuration. The library handles the complexities of loading URLs in development versus files in production, provides type-safe APIs for passing data between main and renderer processes via query parameters, and abstracts away the low-level Electron window management details. It follows a clean architecture with clear separation between main process utilities (registerRoute function) and renderer process components (Router component), supported by shared TypeScript types and utility functions. The library is designed to improve developer experience by eliminating manual management of Electron's loadURL and loadFile methods while maintaining compatibility with react-router-dom's routing patterns.
The LLM identified 4 files worth highlighting for reuse:
This function creates the necessary parameters for Electron's loadFile method when loading local HTML files in production. It takes a file path, window ID, and optional query parameters, then returns a tuple containing the path and options object with the hash properly formatted to include the window ID and query parameters. The implementation correctly handles URL encoding and hash fragment management, demonstrating focused problem-solving for a specific Electron API interaction. It's highly reusable in any Electron application needing to load local files with query parameters.
This function constructs URLs for Electron's loadURL method in development environments. It takes a base URL, window ID, and optional query parameters, then returns a properly formatted URL that includes the window ID in the hash and query parameters in both the base URL and hash (to support both initial load and client-side routing). The function correctly handles URL encoding and avoids double slashes, showcasing attention to detail in URL manipulation. It's a self-contained utility that could be easily extracted for use in any Electron development workflow.
This utility function solves a common problem with URL construction by removing extra slashes that can occur when concatenating URL parts. It uses a precise regular expression to replace sequences of slashes (after the first colon) with a single slash, ensuring clean URLs. The implementation is concise, efficient, and addresses a subtle issue that can cause routing problems in web applications. Its focused nature and lack of dependencies make it trivial to reuse in any project dealing with URL construction or manipulation.
This function creates a new object with all keys converted to lowercase while preserving the original values. It uses Object.keys().reduce() to iterate through the object's keys, creating a new object with transformed keys. The implementation is generic and type-safe, working with any object structure. This solves a common need in applications that require case-insensitive key handling or normalization of object properties. The function is completely isolated, has no external dependencies, and demonstrates clean functional programming principles.