[DRAFT] feat(gatsby-link): force trailing slash option #30230
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 ingatsby-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):
gatsby-config
schemagatsby-link
and it's helper functionsgatsby
core and likely somewhere like thecreatePages
action to write pages to the cache with the enforced optionEach 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
, etcDocumentation
Example
This example clip has
trailingSlash: true
, and showsLink
s 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