Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect match when multiple urlMatch attributes are defined as regular expressions #117

Open
1 of 3 tasks
ltm opened this issue Nov 11, 2020 · 0 comments
Open
1 of 3 tasks
Labels

Comments

@ltm
Copy link

ltm commented Nov 11, 2020

Stencil version:

ionic-docs@1.0.0
└── @stencil/router@1.0.1 

I'm submitting a ... (check one with "x")

Current behavior:
If multiple <stencil-route-link> elements define urlMatch using regular expressions, only one of the elements will correctly match the URL.

Expected behavior:
Multiple <stencil-route-link> elements should be able to define urlMatch using regular expressions.

Steps to reproduce:
Define multiple <stencil-route-link> elements with urlMatch using regular expressions:

<stencil-route-link url="/docs/" urlMatch={[/^\/docs(?!\/(api|components|cli|native)).*$/]}>Guide</stencil-route-link>
<stencil-route-link url="/docs/appflow" urlMatch={[/^\/docs\/appflow(?!\/(tutorial)).*$/]}>Guide</stencil-route-link>

Notice that only one of the two elements will match its URL.

Related code:
The compilePath() function uses JSON.stringify() to generate a cache pattern, cachePattern. If pattern is a regular expression or an array of regular expressions, the cache pattern will contain a non-unique value such as "{}" or "[{}]":

https://github.com/ionic-team/stencil-router/blob/228e1f3888759d651aa436ea3bfe5201e5872803/packages/router/src/utils/match-path.ts#L15-L18

Other information:
Given the pattern [/^\/docs(?!\/(api|components|cli|native)).*$/] the compilePath() function generates the cache pattern "[{}]":

Screen Shot 2020-11-11 at 12 55 16 PM

@claviska claviska changed the title Incorrect match when mulitple urlMatch attributes are defined as regular expressions Incorrect match when multiple urlMatch attributes are defined as regular expressions Nov 11, 2020
@claviska claviska added the bug label Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants