daltonmenezes / electron-router-dom

🧬 A react-router-dom adapter for Electron apps
https://electron-router-dom.daltonmenezes.com
MIT License
125 stars 3 forks source link

Thoughts on a `createElectronRouter` API to support v6.4 data APIs #7

Closed offirgolan closed 1 day ago

offirgolan commented 1 year ago

👋 Hi!

v6.4 of react router introduced data APIs that can only be used via the createBrowserRouter, createHashRouter, and createMemoryRouter.

Thoughts on having this library support a similar wrapper around createHashRouter?

offirgolan commented 1 year ago

Following up on this. This is what I'm currently doing:

import type { FC, ReactNode } from 'react';
import { useMemo } from 'react';
import {
  RouterProvider,
  createHashRouter,
  createRoutesFromChildren,
} from 'react-router-dom';

type Routes = Record<string, ReactNode>;

type AppRouterProps = {
  routes: Routes;
};

function getRouteForCurrentWindow(routes: Routes) {
  const selectAllSlashes = /\//g;
  const windowId = window.location.hash
    .split(selectAllSlashes)?.[1]
    ?.toLowerCase();
  const found = Object.keys(routes).find(
    (key) => key.toLowerCase() === windowId
  );

  return found
    ? {
        basename: `/${windowId}`,
        element: routes[found],
      }
    : null;
}

const AppRouter: FC<AppRouterProps> = ({ routes }) => {
  const router = useMemo(() => {
    const route = getRouteForCurrentWindow(routes);

    return route
      ? createHashRouter(createRoutesFromChildren(route.element), {
          basename: route.basename,
        })
      : null;
  }, [routes]);

  return router ? <RouterProvider router={router} /> : null;
};

export { AppRouter, type AppRouterProps };
daltonmenezes commented 1 year ago

Hi @offirgolan I think I don't quite understand which APIs you are referring to. Could you please talk more about it and include links, so I can take a look? Currently, the way it is, what's the issue using both libs?

offirgolan commented 1 year ago

@daltonmenezes this is documented here

Screen Shot 2022-11-21 at 9 57 53 AM

daltonmenezes commented 1 year ago

Thanks, @offirgolan . Have you had the following type issues? Captura de tela de 2022-11-24 21-12-27

daltonmenezes commented 1 year ago

@offirgolan Ok, the type issue was in v6.4.0, bumping to v6.4.3 solves. 🤔

daltonmenezes commented 1 year ago

@offirgolan using react-router-dom v6.6.0, but we need a electron-router-dom breaking-change to make it work only from that and higher versions. 🤔

https://user-images.githubusercontent.com/1149845/209368713-6914ee48-4707-4baf-87d3-834f6f516dd0.mp4

offirgolan commented 1 year ago

@daltonmenezes thanks for taking the time to look into this 😄

I think a new major version release for this breaking change makes sense since it will be following react-router-dom's new API recommendations.

galetahub commented 1 month ago

@daltonmenezes thanks for your work! Do you have any plans to support react-router-dom 6.x?

daltonmenezes commented 1 month ago

@galetahub soon, I'm finishing the new version of opendocs, after that I can return to electron-router-dom development

daltonmenezes commented 3 weeks ago

@galetahub @offirgolan

The initial decisions I made for v2.0:

what do you think?

code

daltonmenezes commented 2 weeks ago

@galetahub @offirgolan how about this one?

https://github.com/user-attachments/assets/e6065699-e24a-4da9-bc24-f41015fcdd77

daltonmenezes commented 4 days ago

@galetahub @offirgolan v2 release planned for this week! Currently working on site, docs and migration guide!

Captura de Tela 2024-09-08 às 18 11 58
daltonmenezes commented 1 day ago

@galetahub @offirgolan v2 released now! 🎉