From b2dd07dab9f86ceed2058ed66f940e5f4334f1c4 Mon Sep 17 00:00:00 2001 From: Katie Gengler Date: Tue, 18 Aug 2026 16:20:43 -0400 Subject: [PATCH] Add trailing-history location to enforce trailing slashes on URLs --- app/locations/trailing-history.js | 16 ++++++++++++++++ config/environment.js | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 app/locations/trailing-history.js diff --git a/app/locations/trailing-history.js b/app/locations/trailing-history.js new file mode 100644 index 00000000..ef2eadeb --- /dev/null +++ b/app/locations/trailing-history.js @@ -0,0 +1,16 @@ +import HistoryLocation from '@ember/routing/history-location'; + +/* When using this location type with ember-cli dev server, be sure to + set historySupportMiddleware: true in config/environment.js */ + +export default class extends HistoryLocation { + formatURL() { + let url = super.formatURL(...arguments); + + if (url.includes('#')) { + return url.replace(/([^/])#(.*)/, '$1/#$2'); + } else { + return url.replace(/\/?$/, '/'); + } + } +} diff --git a/config/environment.js b/config/environment.js index 90d4a233..600dc997 100644 --- a/config/environment.js +++ b/config/environment.js @@ -11,7 +11,8 @@ module.exports = function (environment) { environment, rootURL: '/', routerRootURL: '/', - locationType: 'history', + locationType: 'trailing-history', + historySupportMiddleware: true, EmberENV: { EXTEND_PROTOTYPES: false, FEATURES: {