( segmentGroup: UrlSegmentGroup, route: Route, segments: UrlSegment[], )
| 81 | } |
| 82 | |
| 83 | export function match( |
| 84 | segmentGroup: UrlSegmentGroup, |
| 85 | route: Route, |
| 86 | segments: UrlSegment[], |
| 87 | ): MatchResult { |
| 88 | if (route.path === '') { |
| 89 | if (route.pathMatch === 'full' && (segmentGroup.hasChildren() || segments.length > 0)) { |
| 90 | return {...noMatch}; |
| 91 | } |
| 92 | |
| 93 | return { |
| 94 | matched: true, |
| 95 | consumedSegments: [], |
| 96 | remainingSegments: segments, |
| 97 | parameters: {}, |
| 98 | positionalParamSegments: {}, |
| 99 | }; |
| 100 | } |
| 101 | |
| 102 | const matcher = route.matcher || defaultUrlMatcher; |
| 103 | const res = matcher(segments, segmentGroup, route); |
| 104 | if (!res) return {...noMatch}; |
| 105 | |
| 106 | const posParams: {[n: string]: string} = {}; |
| 107 | Object.entries(res.posParams ?? {}).forEach(([k, v]) => { |
| 108 | posParams[k] = v.path; |
| 109 | }); |
| 110 | const parameters = |
| 111 | res.consumed.length > 0 |
| 112 | ? {...posParams, ...res.consumed[res.consumed.length - 1].parameters} |
| 113 | : posParams; |
| 114 | |
| 115 | return { |
| 116 | matched: true, |
| 117 | consumedSegments: res.consumed, |
| 118 | remainingSegments: segments.slice(res.consumed.length), |
| 119 | // TODO(atscott): investigate combining parameters and positionalParamSegments |
| 120 | parameters, |
| 121 | positionalParamSegments: res.posParams ?? {}, |
| 122 | }; |
| 123 | } |
| 124 | |
| 125 | export function split( |
| 126 | segmentGroup: UrlSegmentGroup, |
no test coverage detected