Skip to content

Ensure to match against the most specific route#87

Merged
agubler merged 4 commits into
dojo:masterfrom
agubler:routing-configuration
Sep 6, 2018
Merged

Ensure to match against the most specific route#87
agubler merged 4 commits into
dojo:masterfrom
agubler:routing-configuration

Conversation

@agubler
Copy link
Copy Markdown
Member

@agubler agubler commented Aug 29, 2018

Type: feature/bug

The following has been addressed in the PR:

Description:

For routing the first match route specified in the configuration will be considered "the one", even if there is a more exact match in a later route within the configuration.

Assuming a routing configuration:

const config = [
    {
        path: 'foo',
        outlet: 'foo-one'
    },
    {
        path: 'foo',
        outlet: 'foo-two',
        children: [
            {
                path: 'baz',
                outlet: 'baz'
            }
        ]
    },
    {
        path: '{bar}',
        outlet: 'param'
    },
    {
        path: 'bar',
        outlet: 'bar'
    }
];

Current Behaviour

Routing to /bar, should match against the bar outlet as it's more specific (a string literal match) but currently would match against the param outlet because it is registered first.

Routing to /foo/baz would currently match against the outlet, foo-one with a type of partial, rather then correctly matching against the more exact outlet match baz.

Updated Bahaviour

Routing to /bar, will match against the bar outlet as it's more specific (a string literal match).

Routing to /foo/baz will match against outlet baz.

Resolves #83

Comment thread src/routing/Router.ts Outdated
for (let i = 0; i < segments.length; i++) {
const segment = segments[i];
if (typeof segment === 'string' && segment[0] === '{') {
route.score += 7;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to create constants for these numbers so we know what they mean!

Comment thread src/routing/Router.ts
action: 'enter' | 'exit';
}

const ROUTE_SEGMENT_SCORE = 7;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These numbers look fairly arbitrary at first glance. Perhaps a comment to clarify?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They actually are fairly arbitrary, I went for a score that meant we could introduce other types of segments in the future (like maybe wild card, which would have an even smaller score).

@agubler agubler merged commit 1f75a5c into dojo:master Sep 6, 2018
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

Successfully merging this pull request may close these issues.

3 participants