redirect - 如何在 Gatsby 中实现到外部站点的重定向?
问题描述
如何在 Gatsby 中实现从/foobar/
到外部 url的重定向http://example.com/page/
?
对于 Gatsby 2.20.6
,此代码不起作用:
// gatsby-node.js
...
exports.createPages = ({ actions }) => {
const { createRedirect } = actions;
createRedirect({
fromPath: '/foobar/',
isPermanent: true,
redirectInBrowser: true,
toPath: 'http://example.com'
});
});
解决方案
createRedirect
使其他插件有机会在您的静态站点构建期间生成重定向。根据您实际托管该静态站点的位置,进行重定向的过程可能会完全不同。
有关 GatsbycreateRedirect
文档的更多背景信息:
服务器重定向不能开箱即用。您必须有一个插件设置才能将重定向数据与您的托管技术集成
- 用于在 Netlify 上创建用于托管的重定向的插件
- 用于创建重定向以在 Amazon S3 上托管的插件
- 用于创建重定向的通用插件,您可以使用它来执行。在 Surge.sh 上生成重定向
ROUTER
文件,或制作自己的插件
希望有帮助!
推荐阅读
- rt - 删除附件以减少磁盘空间
- python - 错误问题“系列的真值不明确。使用 a.empty、a.bool()、a.item()、a.any() 或 a.all()。”
- c# - Vbs 脚本可以在 CMD 中正常工作,但在代码中不能正常工作
- c# - 如何在 C# 中合并列表中的日期范围
- java - Spring Data JPA Map Query Params with JPA Query 从 Postgresql 检索记录
- python - python django中的基本组层次结构
- mongodb - 无法连接到 abcd:27017,在(轮询后检查套接字是否有错误),原因:连接被拒绝
- c++builder - bcc32c 不保存在 staticobjs 文件夹中
- mysql - 在没有结果的查询中使用 sum() 时返回 null
- python-3.x - 使用python提取pdf中的数字签名