 					matching = false
 					break
 			else
+				if i >= pathParts.length and not defPart.optional
+					matching = false
+					break
 				param[defPart.variable] = pathParts[i]
 		if matching then break
 

		routerDef.pathParts = pathParts = []
		if path
			hasVariable = false
			for part in path.split(/[\/\?\#]/)
				if part.charCodeAt(0) == 58 # `:`
					hasVariable = true
					pathParts.push({
						variable: part.substring(1)
					})
				else
					pathParts.push(part)


	pathParts = if path then path.split(/[\/\?\#]/) else []
	for routerDef in routerRegistry.elements
		gap = routerDef.pathParts.length - pathParts.length
		if 1 < gap < 0 then continue

		matching = true
		param = {}
