rsnext/packages/next/client/components/match-segments.ts
Tim Neutkens 0299f14a7e
Add param names into the tree (#38415)
- Remove cache value that was incorrectly nested deeper
- Remove extra useEffect (already applied during hydration based on the `useReducer` input)
- Add dynamic parameter name into the tree

Follow-up to #37551, cleans up some code and prepares for catch-all and optional catch-all routes.
2022-07-07 13:52:07 +00:00

20 lines
593 B
TypeScript

import { Segment } from '../../server/app-render'
export const matchSegment = (
existingSegment: Segment,
segment: Segment
): boolean => {
// Common case: segment is just a string
if (typeof existingSegment === 'string' && typeof segment === 'string') {
return existingSegment === segment
}
// Dynamic parameter case: segment is an array with param/value. Both param and value are compared.
if (Array.isArray(existingSegment) && Array.isArray(segment)) {
return (
existingSegment[0] === segment[0] && existingSegment[1] === segment[1]
)
}
return false
}