Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Feature: use regexp in routes #283

Merged
merged 5 commits into from
Jul 2, 2018

Conversation

elcobvg
Copy link
Contributor

@elcobvg elcobvg commented Jun 12, 2018

Needed this feature for current project. Using regexp to distinguish routes that would otherwise be clashing. This makes it possible to have routes like so:

index.html
[page].html
[lang([a-z]{2})]/index.html
[lang([a-z]{2})]/[page].html
[category([a-z-]{3,})]/[page].html

Obvious caveat (for now at least): it's not possible to use / or \ in the regexp patterns as that would break the route path.

@elcobvg
Copy link
Contributor Author

elcobvg commented Jun 12, 2018

Tests fail, clearly I've overlooked something. Back to the drawing board...

@Rich-Harris
Copy link
Member

Thanks! This is a neat idea. (Apologies for not commenting sooner, I didn't realise this was no longer WIP.)

Could you fix the whitespace so that it matches the original please (the codebase uses tabs, not spaces)? It's showing changes in lines that haven't actually changed. Also, this'll need some tests, in here 😀

@elcobvg
Copy link
Contributor Author

elcobvg commented Jul 2, 2018

Fixed the whitespace and added some unit tests.
An additional issue: one could use capturing groups in the regexp pattern, which would result in 'nested' params. But webpack chokes on it: throws an error that it can't find the module and I can't figure out why (my webpack knowledge is limited...) Since I have a hard time thinking of a real world use case for this anyway, I've taken the liberty to disallow ( and ) in the regexp pattern for now

@Rich-Harris Rich-Harris merged commit c0c717d into sveltejs:master Jul 2, 2018
@Rich-Harris
Copy link
Member

awesome, thank you!

@elcobvg elcobvg mentioned this pull request Aug 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants