-
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(gatsby): Add support for relative links (#24054)
* Add support for relative links * Review fixes * Changes from review + handle invalid links better * Changes from review + handle invalid links better * Ensure path is tarnslated in more places * Simplify link checks by explicitly checking for http(s) * Fix missing rewrite * Add tests and clear up edge cases * Use explicit protocol list for detecting external links (sorry gopher) * Don't double-prefix absolutified paths * Add e2e tests * Fix tests * Fix calls to deprecated methods * Add docs for relative links * Typo * Clarify
- Loading branch information
Showing
22 changed files
with
511 additions
and
70 deletions.
There are no files selected for viewing
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
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
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
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
23 changes: 23 additions & 0 deletions
23
e2e-tests/development-runtime/src/pages/subdirectory/index.js
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,23 @@ | ||
import * as React from "react" | ||
import { Link, navigate } from "gatsby" | ||
|
||
import Layout from "../../components/layout" | ||
|
||
const IndexPage = () => ( | ||
<Layout> | ||
<h1>Hi people</h1> | ||
<p>Welcome to your new Gatsby site.</p> | ||
<p>Now go build something great.</p> | ||
<Link data-testid="page-2-link" to="./page-2/"> | ||
Go to page 2 | ||
</Link> | ||
<button | ||
data-testid="page-2-button-link" | ||
onClick={() => navigate(`./page-2/`)} | ||
> | ||
Go to page 2 with navigate() | ||
</button> | ||
</Layout> | ||
) | ||
|
||
export default IndexPage |
26 changes: 26 additions & 0 deletions
26
e2e-tests/development-runtime/src/pages/subdirectory/page-1.js
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,26 @@ | ||
import * as React from "react" | ||
import { Link, navigate } from "gatsby" | ||
|
||
import Layout from "../../components/layout" | ||
|
||
const IndexPage = () => ( | ||
<Layout> | ||
<h1>Hi people</h1> | ||
<p>Welcome to your new Gatsby site.</p> | ||
<p>Now go build something great.</p> | ||
<Link data-testid="page-2-link" to="../page-2/"> | ||
Go to page 2 | ||
</Link> | ||
<Link data-testid="page-parent-link" to=".."> | ||
Go up | ||
</Link> | ||
<button | ||
data-testid="page-2-button-link" | ||
onClick={() => navigate(`../page-2/`)} | ||
> | ||
Go to page 2 with navigate() | ||
</button> | ||
</Layout> | ||
) | ||
|
||
export default IndexPage |
16 changes: 16 additions & 0 deletions
16
e2e-tests/development-runtime/src/pages/subdirectory/page-2.js
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,16 @@ | ||
import * as React from "react" | ||
import { Link } from "gatsby" | ||
|
||
import Layout from "../../components/layout" | ||
|
||
const SecondPage = () => ( | ||
<Layout> | ||
<h1>Hi from the second page</h1> | ||
<p>Welcome to page 2</p> | ||
<Link data-testid="index-link" to="../page-1"> | ||
Go back to page 1 | ||
</Link> | ||
</Layout> | ||
) | ||
|
||
export default SecondPage |
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
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
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,23 @@ | ||
import * as React from "react" | ||
import { Link, navigate } from "gatsby" | ||
|
||
import Layout from "../../components/layout" | ||
|
||
const IndexPage = () => ( | ||
<Layout> | ||
<h1>Hi people</h1> | ||
<p>Welcome to your new Gatsby site.</p> | ||
<p>Now go build something great.</p> | ||
<Link data-testid="page-2-link" to="./page-2/"> | ||
Go to page 2 | ||
</Link> | ||
<button | ||
data-testid="page-2-button-link" | ||
onClick={() => navigate(`./page-2/`)} | ||
> | ||
Go to page 2 with navigate() | ||
</button> | ||
</Layout> | ||
) | ||
|
||
export default IndexPage |
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,26 @@ | ||
import * as React from "react" | ||
import { Link, navigate } from "gatsby" | ||
|
||
import Layout from "../../components/layout" | ||
|
||
const IndexPage = () => ( | ||
<Layout> | ||
<h1>Hi people</h1> | ||
<p>Welcome to your new Gatsby site.</p> | ||
<p>Now go build something great.</p> | ||
<Link data-testid="page-2-link" to="../page-2/"> | ||
Go to page 2 | ||
</Link> | ||
<Link data-testid="page-parent-link" to=".."> | ||
Go up | ||
</Link> | ||
<button | ||
data-testid="page-2-button-link" | ||
onClick={() => navigate(`../page-2/`)} | ||
> | ||
Go to page 2 with navigate() | ||
</button> | ||
</Layout> | ||
) | ||
|
||
export default IndexPage |
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,16 @@ | ||
import * as React from "react" | ||
import { Link } from "gatsby" | ||
|
||
import Layout from "../../components/layout" | ||
|
||
const SecondPage = () => ( | ||
<Layout> | ||
<h1>Hi from the second page</h1> | ||
<p>Welcome to page 2</p> | ||
<Link data-testid="index-link" to="../page-1"> | ||
Go back to page 1 | ||
</Link> | ||
</Layout> | ||
) | ||
|
||
export default SecondPage |
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
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
23 changes: 23 additions & 0 deletions
23
e2e-tests/production-runtime/src/pages/subdirectory/index.js
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,23 @@ | ||
import * as React from "react" | ||
import { Link, navigate } from "gatsby" | ||
|
||
import Layout from "../../components/layout" | ||
|
||
const IndexPage = () => ( | ||
<Layout> | ||
<h1>Hi people</h1> | ||
<p>Welcome to your new Gatsby site.</p> | ||
<p>Now go build something great.</p> | ||
<Link data-testid="page-2-link" to="./page-2/"> | ||
Go to page 2 | ||
</Link> | ||
<button | ||
data-testid="page-2-button-link" | ||
onClick={() => navigate(`./page-2/`)} | ||
> | ||
Go to page 2 with navigate() | ||
</button> | ||
</Layout> | ||
) | ||
|
||
export default IndexPage |
26 changes: 26 additions & 0 deletions
26
e2e-tests/production-runtime/src/pages/subdirectory/page-1.js
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,26 @@ | ||
import * as React from "react" | ||
import { Link, navigate } from "gatsby" | ||
|
||
import Layout from "../../components/layout" | ||
|
||
const IndexPage = () => ( | ||
<Layout> | ||
<h1>Hi people</h1> | ||
<p>Welcome to your new Gatsby site.</p> | ||
<p>Now go build something great.</p> | ||
<Link data-testid="page-2-link" to="../page-2/"> | ||
Go to page 2 | ||
</Link> | ||
<Link data-testid="page-parent-link" to=".."> | ||
Go up | ||
</Link> | ||
<button | ||
data-testid="page-2-button-link" | ||
onClick={() => navigate(`../page-2/`)} | ||
> | ||
Go to page 2 with navigate() | ||
</button> | ||
</Layout> | ||
) | ||
|
||
export default IndexPage |
16 changes: 16 additions & 0 deletions
16
e2e-tests/production-runtime/src/pages/subdirectory/page-2.js
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,16 @@ | ||
import * as React from "react" | ||
import { Link } from "gatsby" | ||
|
||
import Layout from "../../components/layout" | ||
|
||
const SecondPage = () => ( | ||
<Layout> | ||
<h1>Hi from the second page</h1> | ||
<p>Welcome to page 2</p> | ||
<Link data-testid="index-link" to="../page-1"> | ||
Go back to page 1 | ||
</Link> | ||
</Layout> | ||
) | ||
|
||
export default SecondPage |
Oops, something went wrong.