@@ -58,6 +58,11 @@ function normalizePackageName(input) {
5858 . toLowerCase ( ) ; // Convert to lowercase
5959}
6060
61+ function shouldUseTrailingSlashForPackageUrl ( ) {
62+ const currentHost = window . location . hostname . toLowerCase ( ) ;
63+ return currentHost . includes ( 'cloudfront.net' ) ;
64+ }
65+
6166function getDashboardPath ( dashboardPath ) {
6267 let normalizedPath = dashboardPath ;
6368
@@ -74,12 +79,36 @@ function getDashboardPath(dashboardPath) {
7479 normalizedPath = '/' + normalizedPath ;
7580 }
7681
77- if ( ! normalizedPath . endsWith ( '/' ) ) {
82+ normalizedPath = normalizedPath . replace ( / \/ + $ / , '' ) || '/' ;
83+
84+ if ( normalizedPath !== '/' && shouldUseTrailingSlashForPackageUrl ( ) ) {
7885 normalizedPath = normalizedPath + '/' ;
7986 }
8087
8188 return normalizedPath ;
8289}
90+
91+ function normalizeDashboardUrlInAddressBar ( ) {
92+ const currentPath = window . location . pathname ;
93+ if ( ! currentPath || currentPath === '/' ) {
94+ return ;
95+ }
96+
97+ let normalizedPath = currentPath . replace ( / \/ + $ / , '' ) || '/' ;
98+ if ( normalizedPath !== '/' && shouldUseTrailingSlashForPackageUrl ( ) ) {
99+ normalizedPath = normalizedPath + '/' ;
100+ }
101+
102+ if ( normalizedPath === currentPath ) {
103+ return ;
104+ }
105+
106+ window . history . replaceState (
107+ window . history . state ,
108+ '' ,
109+ normalizedPath + window . location . search + window . location . hash
110+ ) ;
111+ }
83112
84113function buildPackageDashboardUrl ( packageSlug , dashboardPath ) {
85114 const packageUrl = new URL ( window . location . href ) ;
@@ -755,6 +784,8 @@ function ifNeededMoveFiltersToMobileOrDesktop(state_is_below_breakpoint) {
755784*/
756785document . addEventListener ( "DOMContentLoaded" , function ( ) {
757786
787+ normalizeDashboardUrlInAddressBar ( ) ;
788+
758789
759790
760791 // 1
0 commit comments