sveltejs / sveltejs/kit

Options for Path-Based Trailing Slash

Open
#12,610 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem
  • /posts seems to represent a top-level directory for viewing all posts.
    • /posts/ would be more appropriate.
  • /posts/category-a also represents a directory concept.
    • /posts/category-a/ would be more fitting.
  • /posts/category-a/hello-world is a document.
    • /posts/category-a/hello-world is appropriate.

Now, let's discuss navigation formats.

  • posts
    • When there is no trailing slash, use "/posts"

      • Upward Navigation
        • Absolute path: <a href="/">
        • Relative path: <a href="./"> (Is using ./ for upward navigation a bit strange?)
      • Downward Navigation
        • Absolute path: <a href="/posts/category-a">
        • Relative path: <a href="./posts/category-a"> (Does this seem a bit unusual?)
    • When using a trailing slash, use "/posts/"

      • Upward Navigation
        • Absolute path: <a href="/posts">
        • Relative path: <a href="../"> (This is the correct upward navigation concept.)
      • Downward Navigation
        • Absolute path: <a href="/posts/category-a/">
        • Relative path: <a href="./category-a/">

Going a bit deeper:

  • posts/category-a
    • When there is no trailing slash, use "/posts/category-a"
      • Upward Navigation
        • Absolute path: <a href="/posts">
        • Relative path: <a href="./">
      • Downward Navigation
        • Absolute path: <a href="/posts/category-a/hello-world">
        • Relative path: <a href="./category-a/hello-world"/>
    • When using a trailing slash, use "/posts/category-a/"
      • Upward Navigation
        • Absolute path: <a href="/posts/">
        • Relative path: <a href="../">
      • Downward Navigation
        • Absolute path: <a href="/posts/category-a/hello-world">
        • Relative path: <a href="./hello-world">

When you want to control screen tree access with relative paths, routes composed of slugs might not allow for precise trailing slashes and may require using ignore (which could potentially cause issues in the future).

Describe the proposed solution
export function trailingSlash({ page }) {
  const isDirectory = isDirectory(page.url);
  // or
  // const isCategoryPage ~~
  
  return isDirectory ? 'always' : 'never';
}
Importance

would make my life easier

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the existing trailing-slash handling and the proposed trailingSlash({ page }) entry point, including page.url and the suggested isDirectory check. Done means the issue's directory-style and document-style routes can apply different trailing-slash behavior without relying on imprecise slug-based routing.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
web-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.