Create the content:
Route to it:
Create the routes:
Use the
Create the directory
src/pages/{MarkdownRemark.parent__(File)__relativeDirectory}/
Add the file to the above : {MarkdownRemark.parent__(File)__name}.js
Completed component:
import React from "react"
import { graphql } from "gatsby"
const ComponentName = ({ data }) => {
const { html } = data.markdownRemark;
return (
<div dangerouslySetInnerHTML={{ __html: html }} />
);
}
export const query = graphql`
query($id : String!)
{
markdownRemark(id : { eq : $id })
{
html
}
}
`
export default ComponentName
Check:
Create the first branching point
first.js
import * as React from "react"
import { graphql, Link } from "gatsby"
export default function Page()
{
return (
<div>
This is the page!
</div>
);
}
You can now route to this page via localhost:8000/first
Get the children and render them out
localhost:8000/__grapqhl
Create a query that:
Result:
query {
allFile(filter: {relativeDirectory: {eq: "first"}}) {
nodes {
name
}
}
}
second.js
Copy first.js
name it second.js
Have it render src/pages/second's child files
404 page -> should link to second
Second -> one and second -> two are now navigatable
Make index.js render links to first and second
Clear out index.js
Create a list of pages
Example:
import * as React from "react";
import { Link } from "gatsby";
export default function Index()
{
return (
<div>
This is this index page!
<ul>
<li><Link to="first"> First </Link></li>
<li><Link to="second"> Second </Link></li>
</ul>
</div>
);
}
Test you can navigate to the four pages