【问题标题】:How can I use different dynamic slug url for same component React js?如何为同一组件 React js 使用不同的动态 slug url?
【发布时间】:2021-03-18 13:57:45
【问题描述】:

我的 React 应用中有常见的详细信息视图。 现在我的详细视图 URL 是这样的

blog-details/:blogId

但我想像这样更改网址

host.com/{blog-title}/{blog-type}/{blog-id}

我该怎么做? 我正在使用 react-router,我想使用单个详细信息来查看具有不同动态 URL slug 的组件。

【问题讨论】:

  • 提供更新的path="/:blogTitle/:blogType/:blogId" 道具,像这样?请包含您尝试的Minimal, Complete, and Reproducible 代码示例。
  • @DrewReese 每次博客标题和其他内容不同时都会起作用?
  • 努力改变你的代码来处理你想要的路线/路径?您的问题不清楚。

标签: node.js reactjs react-router react-router-dom


【解决方案1】:

你可以像这样指定一些到组件的路由:

 <Route
    exact
    path={[
      "/:title",
      "/:title/:type",
      "/:title/:type/:id",
    ]}
    component={Blog}
  />

【讨论】:

猜你喜欢
  • 2020-06-19
  • 1970-01-01
  • 2017-03-24
  • 2023-01-22
  • 2021-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-29
相关资源
最近更新 更多