Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Move default route and pathRegex to options param #8

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

bensinober
Copy link

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.

@jikkai jikkai added the pending label Feb 28, 2018
@stalkerg
Copy link

stalkerg commented Mar 1, 2018

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

@bensinober
Copy link
Author

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'

@stalkerg
Copy link

stalkerg commented Mar 1, 2018

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

@bensinober
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants