我希望使用多个JSON文件在盖茨中创建复杂的路由:
第一个JSON文件基于路由:
文件位置: /src/data/route.json
[
{
type: "Article",
title: "Post One",
slug: "/post-one",
data: "post-one.json"
},
{
type: "Course",
title: "Course One",
slug: "/course-one",
data: "course-one.json"
},
...
]
这是包含路线数据的Json文件。
现在,post-one.json
文件中包含呈现该帖子所需的有关该帖子的所有必需数据。
文件位置: /src/data/articles/post-one.json
路线: /后一幅
{
title: "Post One",
head: {
title: "Some title here",
image: "/path/to/image.jpg",
description: "Some description here..."
},
body: {
// Body data here
...
}
}
但是主要的问题现在出现了,因为课程是不同章节的集合。
现在进入主课程页面:
文件位置: /src/data/courses/course-name.json
路线如下: /课程名称
{
title: "Course One",
head: {
title: "Some title here",
image: "/path/to/image.jpg",
description: "Some description here..."
},
info: {
// Some info about the course...
},
chapter: [
{
title: "chapter one",
slug: "/:courseId/chapter-one",
description: "Something about the chapter"
},
{
title: "chapter two",
slug: "/:courseId/chapter-two",
description: "Something about the chapter"
},
...
//Multiple chapters in the same course
]
}
现在各章将具有类似的数据
文件位置: /src/data/chapters/chapter-name.json
路线: / courseId /章节名称
{
title: "Chapter one",
description: "Some description here",
body: {
...
//Content for the body that can be rendered easily
}
}