Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] feat(gatsby-link): force trailing slash option #30230

Closed
wants to merge 2 commits into from

Conversation

gillkyle
Copy link
Contributor

Description

I've been exploring a commonly requested addition to the core framework, adding a config option to force trailing slashes. This PR adds trailingSlash as an option in gatsby-config, that when set to true will enforce a / being appended to any path or page if it hasn't already been added.

This touches several places (and has some that still have to be done):

  • the gatsby-config schema
  • gatsby-link and it's helper functions
  • gatsby core and likely somewhere like the createPages action to write pages to the cache with the enforced option

Each of these places should have some more tests added to verify that all possible paths are still constructed correctly: /test, /test/, /test#hash, /test/#hash, /test?search=asdf, etc

Documentation

Example

This example clip has trailingSlash: true, and shows Links without trailing slashes being SSR'd with a trailing slash, as well as navigating to the proper path with a trailing slash.

CleanShot.2021-03-12.at.15.03.23.mp4

Related Issues

Related to #6365
Related to #3402

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Mar 12, 2021
@LekoArts LekoArts added topic: page creation and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Mar 15, 2021
@LekoArts
Copy link
Contributor

I think trailingSlash: false should also enforce non-trailing slash paths as https://www.gatsbyjs.com/plugins/gatsby-plugin-remove-trailing-slashes/ tries to do.

@pieh
Copy link
Contributor

pieh commented Mar 15, 2021

There are more than just trailing slashes options for customization like that - folks might want to end with .html - like reactjs.org does - https://reactjs.org/docs/react-dom.html

Similarly same page can be constructed by using any of these paths: /foo, /foo/, /foo/index.html so if we want to bake path normalization in - we probably should have config that select one of quite few options and not just trailingSlashes: false:

  • withTrailingSlashes (/foo/)
  • noTrailingSlashes (/foo)
  • html suffix (/foo.html)
  • index.html suffix (/foo/index.html)

And we don't have to support them from start, but config setting should allow us to add more modes without having to add more fields

@LekoArts LekoArts closed this May 6, 2021
@LekoArts LekoArts deleted the feat/trailing-slash-option branch July 2, 2021 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants