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

[Bug]: matchPath not matching if path pattern ends in optional segment #11226

Closed
sahishnu opened this issue Jan 25, 2024 · 1 comment
Closed
Labels

Comments

@sahishnu
Copy link

sahishnu commented Jan 25, 2024

What version of React Router are you using?

6.15.0

Steps to Reproduce

import { matchPath } from 'react-router-dom';

const test1 = matchPath('/profile/:id?', '/profile/ABC-123');
const test2 = matchPath('/profile/:id', '/profile/ABC-123')

console.log(test1) // null
console.log(test2) // PathMatch object

Call matchPath using a path pattern that ends in an optional segment, and a location pathname that includes the optional segment.

Expected Behavior

I would expect matchPath to return a match object for both scenarios.

  1. /profile/:id? should return a match object for path /profile/ABC-123
  2. /profile/id should return a match object for path/profile/ABC-123

Actual Behavior

matchPath returns null for scenario test1.

const test1 = matchPath('/profile/:id?', '/profile/ABC-123')
console.log(test1) // null
@sahishnu sahishnu added the bug label Jan 25, 2024
@brophdawg11
Copy link
Contributor

This was resolved in 6.18.0 via #10768

@brophdawg11 brophdawg11 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 26, 2024
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants