Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty root URL with absolute: false #667

Merged
merged 3 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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