I am developing a static site using JSON data. I replaced the post data in the react-static default sample, and it works fine.
Problem: When I add another route /news
with a bunch of messages in another JSON, the parent route /news
works fine, but the child routes, such as /news/1/
or /news/2/
all go to 404 pages.
In the browser console, I got the error
GET http://localhost:3000/__react-static__/routeInfo/news/1 404 (Not Found)
I do not think these are dynamic routes, as I can get the data before the react app mounted. What should I do to fix that?
In my static.config.js
{
path: '/news',
getData: async () => ({
messages,
}),
children: messages.map(message => ({
path: `/news/${message.ID}`,
template: 'src/containers/Message',
getData: () => ({
message,
}),
})),
}
and I have a Message.js in /src/containers as
import React from "react";
import { useRouteData } from "react-static";
export default () => {
const { message } = useRouteData()
return (
<div>
This is a {message.Title} page!
</div>
)
};
The worked news.js
is as
import React from 'react'
import { useRouteData } from 'react-static'
import { Link } from 'components/Router'
export default function Blog() {
const { messages } = useRouteData()
return (
<div>
<h1>It's news.</h1>
<div>
<a href="#bottom" id="top">
Scroll to bottom!
</a>
</div>
<br />
All Posts:
<ul>
{messages.map(message => (
<li key={message.ID}>
<Link to={`/news/{message.ID}/`}>{message.Title}</Link>
</li>
))}
</ul>
<a href="#top" id="bottom">
Scroll to top!
</a>
</div>
)
}