Skip to content

Feature: routed modals + parameters in modal routes #121

@lauri865

Description

@lauri865

Loving this package so far. I generally prefer to have modals routed though rather than state based in order to have shareable links as a default, rather than state-based (which are only good for global routes).

I have managed to do this myself with custom routes file:
E.g., I have a route in pages/companies/+edit.[id].tsx

And then in routes file I do this to render modals for routes, following the internal matching engine of react-router-dom:

const modalsArray = Object.entries(modalRoutes).map(([path, Component]) => ({
  path: path
    .replace(...patterns.route)
    .replace(...patterns.splat)
    .replace(...patterns.param)
    .replace(/(^|\/)\-\:(:?[\w-]+)(\/|$)/, '$1$2?'),
  element: <Component />,
}))

export const Modals = () => {
  const location = useLocation()
  const matches = matchRoutes(modalsArray, location)
  return renderMatches(matches)
}

Would be great to have this with type-safety out of the box for linkable routes with params.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions