-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(redirects): handle absolute from paths when path prefix is used (#…
…12509) ## Description `toPath` in `createRedirect` handles path prefix properly, however, `fromPath` doesn't. I added the code for supporting the `fromPath` cases. Also, I added test cases of `createRedirect` action for the future. ## Related Issues Fixes #12497
- Loading branch information
Showing
3 changed files
with
463 additions
and
9 deletions.
There are no files selected for viewing
313 changes: 313 additions & 0 deletions
313
packages/gatsby/src/redux/__tests__/__snapshots__/redirects.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,313 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Add redirects allows you to add redirects 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "/old/hello-world", | ||
"isPermanent": false, | ||
"redirectInBrowser": false, | ||
"toPath": "/new/hello-world", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; | ||
|
||
exports[`Add redirects create redirects as permanent 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "/old/hello-world", | ||
"isPermanent": true, | ||
"redirectInBrowser": false, | ||
"toPath": "/new/hello-world", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; | ||
|
||
exports[`Add redirects creates redirects from the URL starts with // 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "//example.com", | ||
"isPermanent": false, | ||
"redirectInBrowser": false, | ||
"toPath": "/new/hello-world-2", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; | ||
|
||
exports[`Add redirects creates redirects from the URL starts with ftp 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "ftp://example.com", | ||
"isPermanent": false, | ||
"redirectInBrowser": false, | ||
"toPath": "/new/hello-world-3", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; | ||
|
||
exports[`Add redirects creates redirects from the URL starts with http 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "http://example.com", | ||
"isPermanent": false, | ||
"redirectInBrowser": false, | ||
"toPath": "/new/hello-world-1", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; | ||
|
||
exports[`Add redirects creates redirects from the URL starts with https 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "https://example.com", | ||
"isPermanent": false, | ||
"redirectInBrowser": false, | ||
"toPath": "/new/hello-world-0", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; | ||
|
||
exports[`Add redirects creates redirects from the URL starts with mailto 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "mailto:[email protected]", | ||
"isPermanent": false, | ||
"redirectInBrowser": false, | ||
"toPath": "/new/hello-world-4", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; | ||
|
||
exports[`Add redirects creates redirects to the URL starts with // 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "/old/hello-world-2", | ||
"isPermanent": false, | ||
"redirectInBrowser": false, | ||
"toPath": "//example.com", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; | ||
|
||
exports[`Add redirects creates redirects to the URL starts with ftp 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "/old/hello-world-3", | ||
"isPermanent": false, | ||
"redirectInBrowser": false, | ||
"toPath": "ftp://example.com", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; | ||
|
||
exports[`Add redirects creates redirects to the URL starts with http 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "/old/hello-world-1", | ||
"isPermanent": false, | ||
"redirectInBrowser": false, | ||
"toPath": "http://example.com", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; | ||
|
||
exports[`Add redirects creates redirects to the URL starts with https 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "/old/hello-world-0", | ||
"isPermanent": false, | ||
"redirectInBrowser": false, | ||
"toPath": "https://example.com", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; | ||
|
||
exports[`Add redirects creates redirects to the URL starts with mailto 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "/old/hello-world-4", | ||
"isPermanent": false, | ||
"redirectInBrowser": false, | ||
"toPath": "mailto:[email protected]", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; | ||
|
||
exports[`Add redirects creates redirects with in-browser redirect option 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "/old/hello-world", | ||
"isPermanent": false, | ||
"redirectInBrowser": true, | ||
"toPath": "/new/hello-world", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; | ||
|
||
exports[`Add redirects with path prefixs allows you to add redirects 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "/blog/old/hello-world", | ||
"isPermanent": false, | ||
"redirectInBrowser": false, | ||
"toPath": "/blog/new/hello-world", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; | ||
|
||
exports[`Add redirects with path prefixs create redirects as permanent 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "/blog/old/hello-world", | ||
"isPermanent": true, | ||
"redirectInBrowser": false, | ||
"toPath": "/blog/new/hello-world", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; | ||
|
||
exports[`Add redirects with path prefixs creates redirects from the URL starts with // 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "//example.com", | ||
"isPermanent": false, | ||
"redirectInBrowser": false, | ||
"toPath": "/blog/new/hello-world-2", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; | ||
|
||
exports[`Add redirects with path prefixs creates redirects from the URL starts with ftp 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "ftp://example.com", | ||
"isPermanent": false, | ||
"redirectInBrowser": false, | ||
"toPath": "/blog/new/hello-world-3", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; | ||
|
||
exports[`Add redirects with path prefixs creates redirects from the URL starts with http 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "http://example.com", | ||
"isPermanent": false, | ||
"redirectInBrowser": false, | ||
"toPath": "/blog/new/hello-world-1", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; | ||
|
||
exports[`Add redirects with path prefixs creates redirects from the URL starts with https 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "https://example.com", | ||
"isPermanent": false, | ||
"redirectInBrowser": false, | ||
"toPath": "/blog/new/hello-world-0", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; | ||
|
||
exports[`Add redirects with path prefixs creates redirects from the URL starts with mailto 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "mailto:[email protected]", | ||
"isPermanent": false, | ||
"redirectInBrowser": false, | ||
"toPath": "/blog/new/hello-world-4", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; | ||
|
||
exports[`Add redirects with path prefixs creates redirects to the URL starts with // 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "/blog/old/hello-world-2", | ||
"isPermanent": false, | ||
"redirectInBrowser": false, | ||
"toPath": "//example.com", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; | ||
|
||
exports[`Add redirects with path prefixs creates redirects to the URL starts with ftp 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "/blog/old/hello-world-3", | ||
"isPermanent": false, | ||
"redirectInBrowser": false, | ||
"toPath": "ftp://example.com", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; | ||
|
||
exports[`Add redirects with path prefixs creates redirects to the URL starts with http 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "/blog/old/hello-world-1", | ||
"isPermanent": false, | ||
"redirectInBrowser": false, | ||
"toPath": "http://example.com", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; | ||
|
||
exports[`Add redirects with path prefixs creates redirects to the URL starts with https 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "/blog/old/hello-world-0", | ||
"isPermanent": false, | ||
"redirectInBrowser": false, | ||
"toPath": "https://example.com", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; | ||
|
||
exports[`Add redirects with path prefixs creates redirects to the URL starts with mailto 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "/blog/old/hello-world-4", | ||
"isPermanent": false, | ||
"redirectInBrowser": false, | ||
"toPath": "mailto:[email protected]", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; | ||
|
||
exports[`Add redirects with path prefixs creates redirects with in-browser redirect option 1`] = ` | ||
Object { | ||
"payload": Object { | ||
"fromPath": "/blog/old/hello-world", | ||
"isPermanent": false, | ||
"redirectInBrowser": true, | ||
"toPath": "/blog/new/hello-world", | ||
}, | ||
"type": "CREATE_REDIRECT", | ||
} | ||
`; |
Oops, something went wrong.