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

[Feature]: useMatch take in array like useRouteMatch #8038

Closed
ghost opened this issue Sep 14, 2021 · 1 comment
Closed

[Feature]: useMatch take in array like useRouteMatch #8038

ghost opened this issue Sep 14, 2021 · 1 comment

Comments

@ghost
Copy link

ghost commented Sep 14, 2021

What is the new or updated feature that you are suggesting?

useMatch able to take an array of different paths to match like useRouteMatch

Why should this feature be included?

Allowing for possible match conditions to meet instead of just one

example:

const routeMatch = useRouteMatch(['/inbox/:id', '/drafts', '/trash']);
  const currentTab = routeMatch?.path;

  return (
    <Tabs value={currentTab}>
      <Tab label="Inbox" value="/inbox/:id" to="/inbox/1" component={Link} />
      <Tab label="Drafts" value="/drafts" to="/drafts" component={Link} />
      <Tab label="Trash" value="/trash" to="/trash" component={Link} />
    </Tabs>
  );
}```
@timdorr
Copy link
Member

timdorr commented Sep 14, 2021

Unfortunately, this would make #8030 significantly more difficult to implement.

Since useMatch just wraps matchPath with a call to useLocation, I would just do this yourself in a map or find loop:

const paths = ['/inbox/:id', '/drafts', '/trash']
const location = useLocation()
const match = paths.find(path => matchPath(path, location.pathname))

I don't think this is something we're going to support in the library itself.

@timdorr timdorr closed this as completed Sep 14, 2021
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

1 participant