Skip to content

Commit

Permalink
Merge pull request #170 from dummdidumm/fix-route-matching
Browse files Browse the repository at this point in the history
Fix route matching
  • Loading branch information
ItalyPaleAle authored Dec 4, 2020
2 parents ae7118f + b9fca47 commit ada4deb
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Router.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -300,16 +300,25 @@ class RouteItem {
* @returns {null|Object.<string, string>} List of paramters from the URL if there's a match, or `null` otherwise.
*/
match(path) {
// If there's a prefix, remove it before we run the matching
// If there's a prefix, check if it matches the start of the path.
// If not, bail early, else remove it before we run the matching.
if (prefix) {
if (typeof prefix == 'string' && path.startsWith(prefix)) {
path = path.substr(prefix.length) || '/'
if (typeof prefix == 'string') {
if (path.startsWith(prefix)) {
path = path.substr(prefix.length) || '/'
}
else {
return null
}
}
else if (prefix instanceof RegExp) {
const match = path.match(prefix)
if (match && match[0]) {
path = path.substr(match[0].length) || '/'
}
else {
return null
}
}
}
Expand Down

0 comments on commit ada4deb

Please sign in to comment.