Skip to content

Commit

Permalink
convert / to #
Browse files Browse the repository at this point in the history
  • Loading branch information
yysun committed Jun 27, 2018
1 parent 41e6f06 commit a235f1b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ app.on('#', _ => { });
app.on('route', url => route(url));

export default function route(url: string) {
if (!url) url = '#';
if (!url || url === '/') url = '#';
if (url.startsWith('#')) {
const [name, ...rest] = url.split('/');
app.run(name, ...rest);
Expand Down
10 changes: 10 additions & 0 deletions tests/router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,14 @@ describe('router', () => {
expect(fn2).toHaveBeenCalledWith('/x', 'y', 'z');
});

it('should convert / to #', () => {
const fn1 = jasmine.createSpy('fn1');
const fn2 = jasmine.createSpy('fn2');
app.on('#', fn1);
app.on('/', fn2);
app.run('route', '/');
expect(fn1).toHaveBeenCalled();
expect(fn2).not.toHaveBeenCalled();
});

});

0 comments on commit a235f1b

Please sign in to comment.