1
Fork 0
mirror of https://github.com/Steffo99/sophon.git synced 2024-12-22 06:44:21 +00:00

🔧 Accept urls without trailing slashes

This commit is contained in:
Steffo 2021-11-08 19:21:46 +01:00 committed by Stefano Pigozzi
parent ad1f12393c
commit fd81459b01
2 changed files with 3 additions and 3 deletions

View file

@ -55,7 +55,7 @@ export function ViewSetRouter<Resource extends DjangoResource>({viewSet, unselec
selection = viewSet.resources?.find(res => res.value[pkKey] === pk) selection = viewSet.resources?.find(res => res.value[pkKey] === pk)
if(!selection) { if(!selection) {
return ( return (
<ErrorBox error={new Error(`Resource not found: ${pk}`)}/> <ErrorBox error={new Error(`Resource "${pk}" of type "${pathSegment}" not found`)}/>
) )
} }
} }

View file

@ -63,7 +63,7 @@ function parsePathSegment({path, parsed, regex, key, next}: ParsePathSegmentConf
// If the match fails, it means the matching is over // If the match fails, it means the matching is over
if(!match || !match.groups) { if(!match || !match.groups) {
parsed.valid = path === "/" parsed.valid = path === "" || path === "/"
return parsed return parsed
} }
@ -73,7 +73,7 @@ function parsePathSegment({path, parsed, regex, key, next}: ParsePathSegmentConf
parsed.count += 1 parsed.count += 1
const results = next.map((func) => { const results = next.map((func) => {
return func(rest, parsed) return func(rest ?? "", parsed)
}).reduce((a, b) => { }).reduce((a, b) => {
return {...a, ...b} return {...a, ...b}
}, {}) }, {})