如何获得以前的网址反应盖茨比 [英] How to get previous url in react gatsby

查看:90
本文介绍了如何获得以前的网址反应盖茨比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常熟悉 React.js 但是 Gatsby

我想检测 Gatsby 中的上一页网址?

I want to detect the previous page URL in Gatsby?

推荐答案

您可以使用链接组件传递状态:

You can pass down state using the Link component:

import React from 'react';
import { Link } from 'gatsby';

const PrevPage = () => (
  <div>
    <Link
      to={`/nextpage`}
      state={{ prevPath: location.pathname }}
    >
      Next Page
    </Link>
  </div>
)

const NextPage = (props) => (
  <div>
    <p>previous path is: {props.location.state.prevPath}</p>
  </div>
);

然后您可以从<$访问 prevPath c $ c> this.props.location.state 在下一页。

You can then access prevPath from this.props.location.state in the next page.

这篇关于如何获得以前的网址反应盖茨比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆