This is more a question than a gatsby related issue. Is there a way to restrict direct access to a page (for instance: /app/download) and to make it available only from other paths inside the website? Thanks beforehand!
This issue talks about how you can pass data using navigateTo API.
src/pages/index.js
import React from 'react'
import Link, { navigateTo } from 'gatsby-link'
const IndexPage = () => (
<div>
<Link to="/secret-page">Regular link</Link>
<button
onClick={() =>
navigateTo({
pathname: '/secret-page',
state: {
showPage: true,
},
})
}
>
Super secret link
</button>
</div>
)
export default IndexPage
src/pages/secret-page.js
import React from 'react'
import Link from 'gatsby-link'
const SecretPage = ({ location }) => {
const { showPage } = location.state || false
return showPage ? (
<div>You have reached a secret page.</div>
) : (
<div>You can鈥檛 access this secret page.</div>
)
}
export default SecretPage
Oh thank you so much, this works like a charm! Any hint on how to do this for a static file as well?
Hmm, I have no experience with that. Perhaps it requires something like authentication.
Most helpful comment
This issue talks about how you can pass data using
navigateToAPI.src/pages/index.jssrc/pages/secret-page.js