我用非常熟悉的React.js,但新Gatsby。
React.js
Gatsby
我要检测中的上一页URL Gatsby?
您可以使用以下Link组件传递状态:
Link
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从this.props.location.state下一页访问。
prevPath
this.props.location.state