Skip to content

Commit

Permalink
fix(trailing-slash): 후행 슬래시 무조건제거 후 redirect하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
mcauto committed Oct 31, 2021
1 parent 1ab998e commit 943a07c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions middleware/trailingSlashRedirect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function ({ route, redirect }) {
if (route.path !== "/" && route.path.endsWith("/")) {
const { path, query, hash } = route;
const nextPath = path.replace(/\/+$/, "") || "/";
const nextRoute = { path: nextPath, query, hash };

redirect(nextRoute);
}
}
3 changes: 2 additions & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ const config: NuxtConfig = {
],
loading: "~/components/loading-bar.vue",
router: {
middleware: ["store"],
middleware: ["store", "trailingSlashRedirect"],
// linkActiveClass: "nuxt-link-active",
trailingSlash: false,
},
pageTransition: {
name: "my-page",
Expand Down

0 comments on commit 943a07c

Please sign in to comment.