Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Error when previewing unpublished pages on localhost that matches the pattern article/:uid #126

Closed
LJNGDAHL opened this issue Jan 10, 2020 · 3 comments · Fixed by #150
Closed

Comments

@LJNGDAHL
Copy link

Description

I want to preview an automatically generated page that matches the pattern /article/:uid. The page is unpublished and I am trying to access it on localhost.

Previewing the same page on my staging site works fine, the page is accessible under /article?uid=baz. But when previewing it on localhost, I am routed to /article/baz. This results in an error since this page is not published.

Steps to Reproduce

Add the following snippet in your gatsby-config.js (together with other settings):

pages: [
          {
            type: 'Page',
            match: '/:uid',
            path: '/page',
            component: require.resolve('./src/templates/page.js')
          },
          {
            type: 'Article',
            match: '/article/:uid',
            path: '/article',
            component: require.resolve('./src/templates/article.js')
          }
        ]

And in your linkResolver.js:

export const linkResolver = doc => {
  if (doc.type === 'article') {
    return `/article/${doc.uid}`
  }

  if (doc.type === 'page') {
    return `/${doc.uid}`
  }

  // Backup for all other types
  return '/'
}

Expected behavior:
Unpublished article pages should accessible for preview on localhost under /article?uid=baz.

Actual behavior:

Unpublished article page is not accessible for preview on localhost.

Versions

"gatsby": "2.18.11"
"prismic-reactjs": "1.1.2",
"gatsby-source-prismic-graphql": "3.4.0-beta.2"
@Mallika1
Copy link

I have the same problem previewing the unpublished documents.

@LJNGDAHL
Copy link
Author

What I've found out is that the problem actually exists on my staging/production sites as well. If I want to preview unpublished documents, I have to:

  1. Click on the preview link
  2. Manually update the url to match the pattern /article?uid=baz
  3. Reload the preview.

If I do this, I preview the document as intended.

@Mallika1
Copy link

Mallika1 commented Mar 29, 2020

when I had top level page created i.e. localhost://article , I was not able to preview the unpublished document . but when I removed article page , it worked for me . Though i need the top level page to be created.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants