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

Modal - React Router implementation #10

Closed
amarmechai opened this issue Aug 27, 2022 · 2 comments
Closed

Modal - React Router implementation #10

amarmechai opened this issue Aug 27, 2022 · 2 comments

Comments

@amarmechai
Copy link
Contributor

can we integrate Modal routes with this project?

Reference : Create contextual modal navigation with React Router V6

IRoute

export interface IRoute {
  ...

  modal?: boolean;
}

We can use this method de get all modal routes

const getModalRoutes = (routes: IRoute[]) => {
  return routes
    .map(route => {
      let modalRooutes: IRoute[] = [];
      const { children, ...rest } = route;

      if (rest.modal)
        modalRooutes.push(rest);

      if (children)
        modalRooutes.push(...getModalRoutes(children));

      return modalRooutes;
    })
    .reduce((accumulator, value) => accumulator.concat(value), []);
}
@nichitaa
Copy link
Owner

Hi @amarmechai, I think it is possible to do so, if it is urgent you could open a PR, as I would have some time only at the end of the week to see how to implement it.

  • But isn't it possible to achieve with query params (to show/close modal) ?

  • As well from the first look, there is a possibility that the use of useLocation hook at the root of our App component would trigger re-renders whenever page changes, which would force all Route components to re-render, (if there would be common layout with some Outlets component, layout would probably re-render, even if it'd be common for a single Route)

const location = useLocation();

@amarmechai
Copy link
Contributor Author

Hi @nichitaa, thank you for the answer.
With query params, it should be possible 🤔 !

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