Skip to content

Commit

Permalink
Remove trailing slashes when on pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
illicitonion committed May 13, 2021
1 parent 4f8b166 commit 9ad4e6b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@ module.exports = {
docs: {
sidebarPath: require.resolve("./sidebars.js"),
editUrl: "https://github.com/CodeYourFuture/Syllabus-V2/edit/master/",
routeBasePath: "/", // Set this value to '/'.
routeBasePath: "/",
},
theme: {
customCss: require.resolve("./src/css/custom.css"),
},
},
],
],
scripts: [
// See comments in static/js/fix-location.js
{
src: "/js/fix-location.js",
async: false,
defer: false
}
],
themeConfig: {
googleAnalytics: {
trackingID: "UA-159979458-2",
Expand Down
8 changes: 8 additions & 0 deletions static/js/fix-location.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Work around https://github.com/CodeYourFuture/syllabus/issues/121 by stripping trailing slashes from paths.
//
// See https://github.com/CodeYourFuture/syllabus/issues/121 and https://github.com/CodeYourFuture/syllabus/pull/254 and https://github.com/facebook/docusaurus/issues/2394 and https://github.com/facebook/docusaurus/issues/3372 for more context.

// This workaround was borrowed from https://github.com/facebook/docusaurus/issues/2394#issuecomment-630638096
if (window && window.location && window.location.pathname.endsWith('/') && window.location.pathname !== '/') {
window.history.replaceState('', '', window.location.pathname.substr(0, window.location.pathname.length - 1))
}

0 comments on commit 9ad4e6b

Please sign in to comment.