DEV Community 👩‍💻👨‍💻

Discussion on: How to redirect in SvelteKit endpoints

danawoodman profile image
Dana Woodman Author

You've added MDSvex with this adder?

And you can't create a file like this src/routes/posts/2021/06/some-post-title/index.svx and then navigate to /posts/2021/06/some-post-title?

spences10 profile image
Scott Spence

Thanks to @askrodney who helped me work this out...

For anyone else that has the same specific issue as me, make a file structure that mirrors the old filing structure, this is in the src/routes folder:

file structure

Then in the index file:

  Redirects from my old blog filing structure yyyy/mm/dd/post-title
  to posts/post-title thanks to rodneylab for the example 👇
<script context="module">
  export async function load({ page }) {
    const { slug } = page.params
    return {
      status: 301,
      redirect: `/posts/${slug}`,
Enter fullscreen mode Exit fullscreen mode