Inconsistent behavior of resulting from/to path in createRedirect #38562
Labels
status: triage needed
Issue or pull request that need to be triaged and assigned to a reviewer
type: bug
An issue or pull request relating to a bug in Gatsby
Preliminary Checks
Description
When pathPrefix is not enabled, the effective
basePath
(/
) is not applied to the path resulting in from/to path's passed to createRedirect passing through unmodified. However, whenpathPrefix
is enabled, the effectivebasePath
(specified by pathPrefix) is applied unless the path is absolute or starts with//
. This leads to inconsistent behavior between the two configuration options.Additionally, the current code (and all subsequent downstream code) assumes that the path values specified in
createRedirect
start with a/
and does not perform any validation and/or apply a leading slash if missing.The behavior should be consistent in all scenarios to avoid different results based on
prefixPath
configuration. Also, given plugins and now adapters can support their own functionality with regards to from/to path, there should be a method for passing through paths unmodified (e.g., regex's).basePath
regardless ofpathPrefix
configuration and ensure leading slash and path separatorspathPrefix
setting (possibly abasePath
property defaulting totrue
on createRedirect that allows bypassing the default functionality of applying thebasePath
by configuring tofalse
)Example:
pathPrefix
disabledpathPrefix
enabled to/blog
Reproduction Link
https://github.com/techfg/gatsby-redirect-prefix-paths-issues
Steps to Reproduce
npm run build
npm run build:pathprefix
Expected Result
pathPrefix
enabled/disabledpathPrefix disabled
pathPrefix /blog
pathPrefix disabled
pathPrefix /blog
Environment
Config Flags
N/A
The text was updated successfully, but these errors were encountered: