svelte-router icon indicating copy to clipboard operation
svelte-router copied to clipboard

Move default route and pathRegex to options param

Open bensinober opened this issue 6 years ago • 4 comments

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.

bensinober avatar Feb 27 '18 20:02 bensinober

It's really important feature but I think you should also keep "default" params.

stalkerg avatar Mar 01 '18 08:03 stalkerg

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'

bensinober avatar Mar 01 '18 09:03 bensinober

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...

stalkerg avatar Mar 01 '18 09:03 stalkerg

Ah, didn't notice that. Will add a commit asap!

bensinober avatar Mar 01 '18 12:03 bensinober