Skip to content

Latest commit

 

History

History
46 lines (35 loc) · 973 Bytes

docusaurus-trailing-slash.md

File metadata and controls

46 lines (35 loc) · 973 Bytes

Fix the Docusaurus trailing slash issue in self-host

Create a file called static/js/fix-location.js with:

if (window && window.location && window.location.pathname.endsWith('/') && window.location.pathname !== '/') {
  window.history.replaceState('', '', window.location.pathname.substr(0, window.location.pathname.length - 1))
}

Load this file as static JS file in docusaurus.config.js:

  scripts: [
    {
      src: '/js/fix-location.js',
      async: false,
      defer: false,
    }
   ],

ref: facebook/docusaurus#2394 (comment)

Another solution to fix this by using busybox

FROM node:16 AS build
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build

# Deployment step

FROM busybox:1.35 as deploy

RUN adduser -D static
USER static
WORKDIR /home/static

COPY --from=build /usr/src/app/build/ ./

EXPOSE 3000

CMD ["busybox", "httpd", "-f", "-v", "-p", "3000"]