我正在使用Gatsby
并且我想使用多语言创建一个站点,到目前为止,我已经定义pages/index.js
了包含以下内容的站点:
import React from "react"
import Layout from "../components/layout/layout"
import BGTState from "../context/bgt/bgtState"
import { Router } from "@reach/router"
import Home from "../components/pages/home"
import Collection from "../components/pages/collection"
import NotFound from "../components/pages/404"
const IndexPage = () => {
return (
<BGTState>
<Layout>
<Router>
<Home path="/" />
<Collection path="collection/:id" />
<NotFound default />
</Router>
</Layout>
</BGTState>
)
}
export default IndexPage
我修改gatsby-node.js
为:
// Implement the Gatsby API onCreatePage. This is
// called after every page is created.
exports.onCreatePage = async ({ page, actions }) => {
const { createPage } = actions
if (page.path === "/") {
page.matchPath = "/*"
createPage(page)
}
}
每个请求都在 上转发index.js
,但存在问题。我正在使用gatsby-plugin-intl
向 url 添加动态前缀的插件,例如:http://localhost:3001/en/
如果我访问http://localhost:3001/en/
,那么我会NotFound
显示组件,因为没有 Route 与 url 匹配。有没有办法为 url 添加前缀并将所有内容重新路由到正确的组件?