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

Default strategy is not necessarily 'ONE', but is 'ALL' when specifying some options but no strategy. #335

Open
sugacube opened this issue Dec 17, 2023 · 0 comments

Comments

@sugacube
Copy link

v8+ documentation says "By default the strategy is equal to "ONE"."
But if some options are specified, but the strategy option is left out, it defaults to 'ALL'.

How to reproduce:

const r1 = new Navigo('/');
r1.on('/x', () => {}) 
r1.on('*', () => {}) 
r1.match('/x').length 

->  result = 1

const r2 = new Navigo('/', { hash: true});
r2.on('/x', () => {}) 
r2.on('*', () => {}) 
r2.match('/x').length 

->  result = 2

What I expected:

  • Only first route is matched, i.e. length of match array = 1

What really happened:

  • All matching routes are returned (length = 2)

Workaround:

  • explicit include "strategy: 'ONE'" in constructor.

    const r3 = new Navigo('/', { hash: true, strategy: 'ONE'});
    r3.on('/x', () => {})
    r3.on('*', () => {})
    r3.match('/x').length

Remark:
The culprit seems to be when options are provided, strategy remains unset if not explicitly provided.
In "matchPathToRegisteredRoutes.ts", line "if (context.resolveOptions.strategy === "ONE") {" will fail, effectively matching all routes.
At first sight, this initialisation seems unharmful for the other options, and linkselector is explicitly being checked for being unset in "findLinks()".

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

No branches or pull requests

1 participant