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