Skip to content

Commit

Permalink
Update sub-route when route could be matched
Browse files Browse the repository at this point in the history
  • Loading branch information
TimvdLippe committed Apr 10, 2016
1 parent 4682d88 commit b57253b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
7 changes: 2 additions & 5 deletions carbon-route.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
return;
}

if (!path) {
if (path === undefined || path === null) {
this.__resetProperties();
return;
}
Expand Down Expand Up @@ -266,10 +266,7 @@
}

matched = matched.join('/');
var tailPath = remainingPieces.join('/');
if (remainingPieces.length > 0) {
tailPath = '/' + tailPath;
}
var tailPath = '/' + remainingPieces.join('/');

this._skipMatch = true;
this._matched = matched;
Expand Down
29 changes: 27 additions & 2 deletions test/carbon-route.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
route="{{fooRoute}}"
data="{{bazData}}">
</carbon-route>

<carbon-route
pattern="/:page"
route="{{fooRoute}}"
data="{{pageData}}">
</carbon-route>
</template>
</test-fixture>
<script>
Expand All @@ -63,7 +69,8 @@
return {
foo: routes[0],
bar: routes[1],
baz: routes[2]
baz: routes[2],
page: routes[3]
};
}

Expand Down Expand Up @@ -105,7 +112,7 @@
route.set('route.path', '/user/toriel');
expect(route.tail).to.be.deep.equal({
prefix: '/user/toriel',
path: '',
path: '/',
__queryParams: {}
});
});
Expand Down Expand Up @@ -208,6 +215,24 @@
routes.bar.set('data.bar', 'cba');
expect(routes.foo.route.path).to.be.eql('/foo/123/baz/zyx');
});

suite('updates when path could be matched', function() {
test('with literal part', function() {
var routes = fixtureChainedRoutes({ path: '/foo/123/bar/' });

expect(routes.bar.active).to.be.eql(true);
routes.bar.set('data.bar', 'zyx');
expect(routes.foo.route.path).to.be.eql('/foo/123/bar/zyx');
});

test('with only match', function() {
var routes = fixtureChainedRoutes({ path: '/foo/123' });

expect(routes.page.active).to.be.eql(true);
routes.page.set('data.page', 'page1');
expect(routes.foo.route.path).to.be.eql('/foo/123/page1');
});
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/test-app-example-1.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
});
expect(exampleApp.userRoute).to.be.deep.eq({
prefix: '/user',
path: '',
path: '/',
__queryParams: {}
});

Expand Down

0 comments on commit b57253b

Please sign in to comment.