svelte-router
svelte-router copied to clipboard
Move default route and pathRegex to options param
Hi, thanks for this super-simple route implementation for svelte! Would be nice to be able to change the regex match of path param, so I took the liberty of moving the constant (along with default route) to an optional param. Feel free to disagree.
It's really important feature but I think you should also keep "default" params.
Hi, by default you mean fallbacks? If so, they are moved to createRouter:
const pathRegex = options['pathRegex'] ? options['pathRegex'] : '[a-zA-Z]+'
const defaultRoute = options['defaultRoute'] ? options['defaultRoute'] : 'default'
yes but for default we should return ([a-zA-Z0-9]+) instead '[a-zA-Z]+':
const getPathRegex = (sections) => {
return sections.map((value) => {
if (value.match(new RegExp(`:${DYNAMIC_PATH_REGEX}`)) !== null) {
return `([a-zA-Z0-9]+)`
}
return value
}).join('\\/')
}
but your code now has same regexp...
Ah, didn't notice that. Will add a commit asap!