fix: fix the pass route not work with paths ending with "/"
This commit is contained in:
parent
f7a6bc4f6a
commit
db5c598a81
1 changed files with 3 additions and 2 deletions
|
@ -72,13 +72,14 @@ function svrouter() {
|
||||||
} else if (callback && typeof path !== "string") {
|
} else if (callback && typeof path !== "string") {
|
||||||
throw new Error("The path must be a function");
|
throw new Error("The path must be a function");
|
||||||
}
|
}
|
||||||
|
const realPath = callback ? path.replace(/\/+$/, "") : null;
|
||||||
|
|
||||||
routes.push({
|
routes.push({
|
||||||
method: null,
|
method: null,
|
||||||
pathFunction: callback
|
pathFunction: callback
|
||||||
? (checkedPath) =>
|
? (checkedPath) =>
|
||||||
checkedPath == path ||
|
checkedPath == realPath ||
|
||||||
checkedPath.substring(0, path.length + 1) == path + "/"
|
checkedPath.substring(0, realPath.length + 1) == realPath + "/"
|
||||||
? {
|
? {
|
||||||
path: checkedPath,
|
path: checkedPath,
|
||||||
params: null
|
params: null
|
||||||
|
|
Loading…
Reference in a new issue