-
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.
Update redirects example for Gatsby v2 (#5681)
- Loading branch information
1 parent
924581a
commit 667d079
Showing
7 changed files
with
150 additions
and
136 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
File renamed without changes.
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
File renamed without changes.
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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
import React from "react" | ||
import Layout from "../components/layout" | ||
|
||
const NotFoundPage = () => ( | ||
<div> | ||
<h1>NOT FOUND</h1> | ||
<p>You just hit a route that doesn't exist... the sadness.</p> | ||
</div> | ||
<Layout> | ||
<div> | ||
<h1>NOT FOUND</h1> | ||
<p>You just hit a route that doesn't exist... the sadness.</p> | ||
</div> | ||
</Layout> | ||
) | ||
|
||
export default NotFoundPage |
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 |
---|---|---|
@@ -1,76 +1,79 @@ | ||
import React from "react" | ||
import { Link } from "gatsby" | ||
import Layout from "../components/layout" | ||
|
||
const IndexPage = () => ( | ||
<div> | ||
<h1>Hi people</h1> | ||
<p> | ||
Welcome to your new Gatsby | ||
<code> | ||
<a href="https://github.com/gatsbyjs/gatsby/search?utf8=%E2%9C%93&q=createRedirect"> | ||
createRedirect | ||
<Layout> | ||
<div> | ||
<h1>Hi people</h1> | ||
<p> | ||
Welcome to your new Gatsby | ||
<code> | ||
<a href="https://github.com/gatsbyjs/gatsby/search?utf8=%E2%9C%93&q=createRedirect"> | ||
createRedirect | ||
</a> | ||
</code> | ||
<a href="https://www.gatsbyjs.org/docs/bound-action-creators/"> | ||
bound action creator | ||
</a> | ||
</code> | ||
<a href="https://www.gatsbyjs.org/docs/bound-action-creators/"> | ||
bound action creator | ||
</a> | ||
{` `} | ||
example. | ||
</p> | ||
<p> | ||
These paths redirect{` `} | ||
<Link activeClassName="selected" to="/"> | ||
here | ||
</Link>: | ||
</p> | ||
<ul> | ||
<li> | ||
<Link to="/grape">/grape</Link> | ||
</li> | ||
<li> | ||
<Link to="/juice">/juice</Link> | ||
</li> | ||
</ul> | ||
<p> | ||
The{` `} | ||
<Link activeClassName="selected" to="/"> | ||
here | ||
</Link> | ||
{` `} | ||
link uses{` `} | ||
<a href="https://www.gatsbyjs.org/packages/gatsby-link/">gatsby-link</a> | ||
{` `} | ||
<code>activeClassName</code> | ||
support derived from{` `} | ||
<a href="https://github.com/ReactTraining/react-router/blob/master/packages/react-router-dom/docs/api/NavLink.md"> | ||
React Router’s NavLink component | ||
</a> | ||
{` `} | ||
to apply the <code>selected</code> | ||
class to links that match to the active path, and{` `} | ||
<code>import './selected.css'</code> | ||
in <code>/src/layouts/index.js</code> | ||
makes the <code>.selected {`{ color: #396; }`}</code> style | ||
declaration globally available to both pages. | ||
</p> | ||
<p>These paths redirect to page 2:</p> | ||
<ul> | ||
<li> | ||
<Link to="/blue">/blue</Link> | ||
</li> | ||
<li> | ||
<Link to="/randirect">/randirect</Link> | ||
</li> | ||
<li> | ||
<Link to="/randorect">/randorect</Link> | ||
</li> | ||
</ul> | ||
<p> | ||
Check <code>/gatsby-node.js</code> to see how. Then go build | ||
something great. | ||
</p> | ||
<Link to="/page-2/">Go to page 2</Link> | ||
</div> | ||
{` `} | ||
example. | ||
</p> | ||
<p> | ||
These paths redirect{` `} | ||
<Link activeClassName="selected" to="/"> | ||
here | ||
</Link>: | ||
</p> | ||
<ul> | ||
<li> | ||
<Link to="/grape">/grape</Link> | ||
</li> | ||
<li> | ||
<Link to="/juice">/juice</Link> | ||
</li> | ||
</ul> | ||
<p> | ||
The{` `} | ||
<Link activeClassName="selected" to="/"> | ||
here | ||
</Link> | ||
{` `} | ||
link uses{` `} | ||
<a href="https://www.gatsbyjs.org/packages/gatsby-link/">gatsby-link</a> | ||
{` `} | ||
<code>activeClassName</code> | ||
support derived from{` `} | ||
<a href="https://github.com/ReactTraining/react-router/blob/master/packages/react-router-dom/docs/api/NavLink.md"> | ||
React Router’s NavLink component | ||
</a> | ||
{` `} | ||
to apply the <code>selected</code> | ||
class to links that match to the active path, and{` `} | ||
<code>import './selected.css'</code> | ||
in <code>/src/layouts/index.js</code> | ||
makes the <code>.selected {`{ color: #396; }`}</code> style | ||
declaration globally available to both pages. | ||
</p> | ||
<p>These paths redirect to page 2:</p> | ||
<ul> | ||
<li> | ||
<Link to="/blue">/blue</Link> | ||
</li> | ||
<li> | ||
<Link to="/randirect">/randirect</Link> | ||
</li> | ||
<li> | ||
<Link to="/randorect">/randorect</Link> | ||
</li> | ||
</ul> | ||
<p> | ||
Check <code>/gatsby-node.js</code> to see how. Then go build | ||
something great. | ||
</p> | ||
<Link to="/page-2/">Go to page 2</Link> | ||
</div> | ||
</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 |
---|---|---|
@@ -1,67 +1,70 @@ | ||
import React from "react" | ||
import { Link } from "gatsby" | ||
import Layout from "../components/layout" | ||
|
||
const SecondPage = () => ( | ||
<div> | ||
<h1>Hi from the second page</h1> | ||
<p> | ||
Welcome to page 2 of your | ||
<code> | ||
<a href="https://github.com/gatsbyjs/gatsby/search?utf8=%E2%9C%93&q=createRedirect"> | ||
createRedirect | ||
<Layout> | ||
<div> | ||
<h1>Hi from the second page</h1> | ||
<p> | ||
Welcome to page 2 of your | ||
<code> | ||
<a href="https://github.com/gatsbyjs/gatsby/search?utf8=%E2%9C%93&q=createRedirect"> | ||
createRedirect | ||
</a> | ||
</code> | ||
<a href="https://www.gatsbyjs.org/docs/bound-action-creators/"> | ||
bound action creator | ||
</a> | ||
</code> | ||
<a href="https://www.gatsbyjs.org/docs/bound-action-creators/"> | ||
bound action creator | ||
</a> | ||
example. | ||
</p> | ||
<p> | ||
These paths redirect{` `} | ||
<Link activeClassName="selected" to="/page2/"> | ||
here | ||
</Link>: | ||
</p> | ||
<ul> | ||
<li> | ||
<Link to="/donut">/donut</Link> | ||
</li> | ||
<li> | ||
<Link to="/page2">/page2</Link> (missing hyphen between page and 2 and | ||
trailing slash) | ||
</li> | ||
<li> | ||
<Link to="/page2/">/page2/</Link> (missing hyphen between page and 2) | ||
</li> | ||
</ul> | ||
<p> | ||
Note how the trailing slash changes disappears and reappears in the | ||
address bar path when following the last two <code>/page2</code> | ||
links above. This demonstrates the need to handle | ||
trailing-slashed and non-trailing-slashed versions of{` `} | ||
<code>fromPath</code> | ||
separately when using <code>createRedirect</code> in{` `} | ||
<code>/gatsby-node.js</code>. Gatsby serves{` `} | ||
<a href="https://www.gatsbyjs.org/docs/building-with-components/"> | ||
page components | ||
</a> | ||
at either version by default, but we need to explicitly redirect | ||
both versions independently (More on{` `} | ||
<a href="https://www.gatsbyjs.org/docs/creating-and-modifying-pages/#removing-trailing-slashes"> | ||
handling trailing slashes | ||
</a>). | ||
</p> | ||
<p>These paths redirect to the homepage:</p> | ||
<ul> | ||
<li> | ||
<Link to="/orange">/orange</Link> | ||
</li> | ||
<li> | ||
<Link to="/soda">/soda</Link> | ||
</li> | ||
</ul> | ||
<Link to="/">Go back to the homepage</Link> | ||
</div> | ||
example. | ||
</p> | ||
<p> | ||
These paths redirect{` `} | ||
<Link activeClassName="selected" to="/page2/"> | ||
here | ||
</Link>: | ||
</p> | ||
<ul> | ||
<li> | ||
<Link to="/donut">/donut</Link> | ||
</li> | ||
<li> | ||
<Link to="/page2">/page2</Link> (missing hyphen between page and 2 and | ||
trailing slash) | ||
</li> | ||
<li> | ||
<Link to="/page2/">/page2/</Link> (missing hyphen between page and 2) | ||
</li> | ||
</ul> | ||
<p> | ||
Note how the trailing slash changes disappears and reappears in the | ||
address bar path when following the last two <code>/page2</code> | ||
links above. This demonstrates the need to handle | ||
trailing-slashed and non-trailing-slashed versions of{` `} | ||
<code>fromPath</code> | ||
separately when using <code>createRedirect</code> in{` `} | ||
<code>/gatsby-node.js</code>. Gatsby serves{` `} | ||
<a href="https://www.gatsbyjs.org/docs/building-with-components/"> | ||
page components | ||
</a> | ||
at either version by default, but we need to explicitly redirect | ||
both versions independently (More on{` `} | ||
<a href="https://www.gatsbyjs.org/docs/creating-and-modifying-pages/#removing-trailing-slashes"> | ||
handling trailing slashes | ||
</a>). | ||
</p> | ||
<p>These paths redirect to the homepage:</p> | ||
<ul> | ||
<li> | ||
<Link to="/orange">/orange</Link> | ||
</li> | ||
<li> | ||
<Link to="/soda">/soda</Link> | ||
</li> | ||
</ul> | ||
<Link to="/">Go back to the homepage</Link> | ||
</div> | ||
</Layout> | ||
) | ||
|
||
export default SecondPage |