Skip to content

Commit 853d297

Browse files
committed
feat: add setPath method
1 parent d6cd731 commit 853d297

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

modules/RouteNode.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ export default class RouteNode {
4545
return this;
4646
}
4747

48+
setPath(path = '') {
49+
this.path = path;
50+
this.parser = path ? new Path(path) : null;
51+
}
52+
4853
add(route, cb = noop) {
4954
let originalRoute;
5055
if (route === undefined || route === null) return;

test/main.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,17 @@ describe('RouteNode', function () {
357357
node.buildPath('route', { b: '2' }).should.equal('/path?b=2');
358358
node.buildPath('route', { a: '1', b: '2' }).should.equal('/path?a=1&b=2');
359359
});
360+
361+
it('should be able to modify a path', function () {
362+
var node = new RouteNode('', '', [
363+
new RouteNode('route', '/path')
364+
]);
365+
366+
node.buildPath('route').should.equal('/path');
367+
node.buildPath('route', { param: '1' }).should.equal('/path');
368+
node.setPath('?param');
369+
node.buildPath('route', { param: '1' }).should.equal('/path?param=1');
370+
});
360371
});
361372

362373

0 commit comments

Comments
 (0)