Возьмите эти два URL:
const url1 = '/user/{username}/edit'
const url2 = '/user/harry/edit'
Есть ли решение, чтобы сопоставить эти два URL-адреса и вернуть true, если они похожи?
Я пробовал следующее и должно быть худшее решение:
const url1 = '/user/{username}/edit'
const url2 = '/user/harry/edit'
const split1 = url1.split('/')
const split2 = url2.split('/')
let matchCount = 0
let notMatchedCount = 0
split1.map(x => {
if(x === split2[x]) {
matchCount++
} else {
notMatchedCount++
}
})
if(matchCount > notMatchedCount) {
console.log('Match Found')
} else {
console.log('Match not found')
}
EDIT
Решением было использование PathToRegExp пакета! Спасибо @ChiragRavindra!