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

Ensure to match against the most specific route #87

Merged
merged 4 commits into from
Sep 6, 2018

Conversation

agubler
Copy link
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

onExit
};
if (defaultRoute) {
this._defaultOutlet = outlet;
}
for (let i = 0; i < segments.length; i++) {
const segment = segments[i];
if (typeof segment === 'string' && segment[0] === '{') {
route.score += 7;
Copy link
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!

@@ -24,6 +25,9 @@ export interface OutletEvent extends EventObject<string> {
action: 'enter' | 'exit';
}

const ROUTE_SEGMENT_SCORE = 7;
Copy link
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
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