Skip to content

Deduplicate multiple consecutive slashes in a current URL without reloading a page — useful for GitHub Pages

License

Notifications You must be signed in to change notification settings

shinnn/slash-deduplication

Repository files navigation

slash-deduplication

npm version Build Status Build status

Deduplicate multiple consecutive slashes in a current URL without reloading a page

Installation

Use npm.

npm install slash-deduplication

Usage

Once the HTML page loads the script and if the current location.pathname includes multiple consecutive /, it replaces the current URL with a duplicate-/-free one.

(async () => {
  location.href; //=> 'https://example.org/a//b/c//d////'
  await import('slash-deduplication');
  location.href; //=> 'https://example.org/a/b/c/d/'
})();

It only modifies the path of URL. Original fragment identifier and parameters are preserved.

(async () => {
  location.href; //=> 'https://example.org////////page#a//b&c=d//e'
  await import('slash-deduplication');
  location.href; //=> 'https://example.org/page#a//b&c=d//e'
})();

This library is suitable for static site hosting service where server-side redirection is not user-unconfigurable, for example GitHub Pages.

License

ISC License © 2018 Shinnosuke Watanabe

About

Deduplicate multiple consecutive slashes in a current URL without reloading a page — useful for GitHub Pages

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published