栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在盖茨比中创建动态路线

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在盖茨比中创建动态路线

您必须明确告诉gatsby路径应该是动态的。从文档:

// gatsby-node.js// Implement the Gatsby API “onCreatePage”. This is// called after every page is created.exports.onCreatePage = async ({ page, actions }) => {  const { createPage } = actions  // page.matchPath is a special key that's used for matching pages  // only on the client.  if (page.path.match(/^/app/)) {    page.matchPath = "/app/*"    // Update the page.    createPage(page)  }}

然后您可以在其中使用动态路由

src/pages/app.js

import { Router } from "@reach/router"const SomeSubPage = props => {  return <div>Hi from SubPage with id: {props.id}</div>}const App = () => (  <Layout>    <link to="/app/1">First item</link>{" "}    <link to="/app/2">Second item</link>{" "}    <Router>      // ...dynamic routes here      <SomeSubPage path="/app/:id" />    </Router>  </Layout>)export default App

/app/*
现在,将动态处理所有内容。您应该在道具中照常找到自己的ID。

看看他们的身份验证示例https://github.com/gatsbyjs/gatsby/tree/master/examples/simple-
auth



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/448900.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号