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

Trim slashes between origin and optional first param #637

Merged
merged 3 commits into from
May 5, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Quick fix
  • Loading branch information
bakerkretzmar committed May 5, 2023
commit bbb41c5ddbeb23cdcd34ecfc7e50f5c064f3396f
10 changes: 6 additions & 4 deletions src/js/Route.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ export default class Route {
* @return {String} Route template.
*/
get template() {
return `${this.origin}/${this.definition.uri}`.replace(/\/+$/, '');
}

get origin() {
// If we're building just a path there's no origin, otherwise: if this route has a
// domain configured we construct the origin with that, if not we use the app URL
const origin = !this.config.absolute ? '' : this.definition.domain
return !this.config.absolute ? '' : this.definition.domain
? `${this.config.url.match(/^\w+:\/\//)[0]}${this.definition.domain}${this.config.port ? `:${this.config.port}` : ''}`
: this.config.url;

return `${origin}/${this.definition.uri}`.replace(/\/+$/, '');
}

/**
Expand Down Expand Up @@ -101,6 +103,6 @@ export default class Route {
}

return encodeURIComponent(params[segment] ?? '');
}).replace(/\/+$/, '');
}).replace(`${this.origin}//`, `${this.origin}/`).replace(/\/+$/, '');
}
}