troch / route-node

A package to create a tree of named routes
MIT License
20 stars 15 forks source link

Children are not matched when parent's sibling has a shorter path #18

Open whs opened 6 years ago

whs commented 6 years ago

Sorry for the title, I don't know how to describe this problem clearly.

This is probably related to #17. The case can be demonstrated by this test:

it('should able to match longer subpath that has similar path on the root', ( ) => {

    const node = new RouteNode('', '', [
        new RouteNode('a', '/:x/:y'),
        new RouteNode('b', '/', [
            new RouteNode('c', 'a/b/c'),
        ]),
    ]);

    withoutMeta(node.matchPath('/a/b/c')).should.eql({ name: 'c', params: { } });

});

matchPath will return {} even though there is a route for /a/b/c

troch commented 6 years ago

That looks like an edge case because /:x/:y (a) is matched before / (b). I'm not sure I can do anything about it.

shavyg2 commented 5 years ago

Why is a matched? It has no children that has that route?