Skip to content

Commit

Permalink
Merge pull request #667 from tighten/jbk/root-url-fix
Browse files Browse the repository at this point in the history
Fix empty root URL with `absolute: false`
  • Loading branch information
bakerkretzmar authored Sep 15, 2023
2 parents f2b43c0 + 224eca7 commit cd1ebc7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/js/Route.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export default class Route {
* @return {String} Route template.
*/
get template() {
return `${this.origin}/${this.definition.uri}`.replace(/\/+$/, '');
const template = `${this.origin}/${this.definition.uri}`.replace(/\/+$/, '');

return template === '' ? '/' : template;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions tests/js/route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,10 @@ describe('route()', () => {
same(route('home'), 'https://ziggy.dev');
});

test('can generate a relative URL to a root path', () => {
same(route('home', undefined, false), '/');
});

// @todo duplicate
test('can ignore an optional parameter', () => {
same(route('optional', { id: 123 }), 'https://ziggy.dev/optional/123');
Expand Down

0 comments on commit cd1ebc7

Please sign in to comment.