# I changed the UID, but page with old UID is still active?

**URL:** <https://community.prismic.io/t/i-changed-the-uid-but-page-with-old-uid-is-still-active/2426>\
**Category:** Developing with Prismic\
**Tags:** nextjs\
**Created:** [October 25, 2020, 5:31pm UTC](https://community.prismic.io/t/i-changed-the-uid-but-page-with-old-uid-is-still-active/2426 "2020-10-25T17:31:03Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![kris](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@kris](https://community.prismic.io/u/kris)\
**Post date:** [October 25, 2020, 5:31pm UTC](https://community.prismic.io/t/i-changed-the-uid-but-page-with-old-uid-is-still-active/2426/1 "2020-10-25T17:31:04Z")

</div>

Hello everyone,

My client had a page [https://www.hivery.com/david-buckley-retail-publix](https://www.hivery.com/david-buckley-retail-publix) but he decided to change the UID to [https://www.hivery.com/david-buckley-retail-kroger](https://www.hivery.com/david-buckley-retail-kroger)

He said that he doesn't wish the old pages to still be active - they should either 404 or redirect to the current UID.

I am using NextJS and my getStaticPaths() function looks like this:

```
export async function getStaticPaths() {

```

const documents = await queryRepeatableDocuments((doc) =\> doc.type === "page")  
console.log(documents)  
return {  
paths: documents.map((doc) =\> `/${doc.uid.split("__").join("/")}`),  
fallback: true,  
}  
}

It should also be noted that I use "fallback: true" in my getStaticPaths() which seems to affect this behaviour. But I think I still need this boolean to be true (I use it to generate landing pages from the root path, such as these urls above, I do it within [...uid].js)

Update: it does seem the the fallback option is what is causing the old page to be rendered. Can somebody explain how this is possible. Since I have updated the UID, how does my nextjs app knows that there has been a page with this UID and this content. (This is my first Nextjs website, apologies)

I was debugging what is going on in getStaticProps function and my that I search by is indeed david-buckley-retail-publix (the old UID), but then the pageDocument that I get after I search using .getByUID() has a UID of "david-buckley-retail-kroger" (the new UID page)

Any idea how I can fix this behaviour?

Many thanks,  
Kris

---

<div class="post-metadata">

**Author:** ![marcellothearcane](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/marcellothearcane/32/224_2.png) [@marcellothearcane](https://community.prismic.io/u/marcellothearcane)\
**Post date:** [October 26, 2020, 7:37am UTC](https://community.prismic.io/t/i-changed-the-uid-but-page-with-old-uid-is-still-active/2426/2 "2020-10-26T07:37:47Z")

</div>

Does this help?

> **[Error: This value is already used by another document](https://user-guides.prismic.io/en/articles/1546584-error-this-value-is-already-used-by-another-document)**
>
> This article explains what to do when a UID value is already in use by another document

---

<div class="post-metadata">

**Author:** ![Phil](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/phil/32/14_2.png) [@Phil](https://community.prismic.io/u/Phil)\
**Post date:** [November 6, 2020, 3:39pm UTC](https://community.prismic.io/t/i-changed-the-uid-but-page-with-old-uid-is-still-active/2426/4 "2020-11-06T15:39:13Z")

</div>

This issue has been closed due to inactivity. [Flag to reopen](https://community.prismic.io/t/re-open-a-thread/2175).

---

<div class="post-metadata">

**Author:** ![Phil](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/phil/32/14_2.png) [@Phil](https://community.prismic.io/u/Phil)\
**Post date:** [November 13, 2020, 9:53am UTC](https://community.prismic.io/t/i-changed-the-uid-but-page-with-old-uid-is-still-active/2426/5 "2020-11-13T09:53:36Z")

</div>

Re-opened for you now @kris

---

<div class="post-metadata">

**Author:** ![Phil](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/phil/32/14_2.png) [@Phil](https://community.prismic.io/u/Phil)\
**Post date:** [November 13, 2020, 11:18am UTC](https://community.prismic.io/t/i-changed-the-uid-but-page-with-old-uid-is-still-active/2426/7 "2020-11-13T11:18:31Z")

</div>



---

<div class="post-metadata">

**Author:** ![kris](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@kris](https://community.prismic.io/u/kris)\
**Post date:** [November 13, 2020, 11:33am UTC](https://community.prismic.io/t/i-changed-the-uid-but-page-with-old-uid-is-still-active/2426/8 "2020-11-13T11:33:14Z")

</div>

@marcellothearcane I am not sure if this will solve my problem.

My client creates a lot of unique landing pages which he duplicates previous pages and he changes the URL.

So for example, he has a page with URL "/linkedin-proposal", he sends it across, he makes the call/deal and then 5 days later, he wants to create a new page called "/microsoft-proposal" which is almost exactly the same as the linkedin proposal page, but with different copy.

The problem is that the old linkedin proposal page is still working, but this time is showing microsoft proposal copy, because it fallsback to the new copy.

Any advice of how I can tackle this?

---

<div class="post-metadata">

**Author:** ![marcellothearcane](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/marcellothearcane/32/224_2.png) [@marcellothearcane](https://community.prismic.io/u/marcellothearcane)\
**Post date:** [November 13, 2020, 1:13pm UTC](https://community.prismic.io/t/i-changed-the-uid-but-page-with-old-uid-is-still-active/2426/9 "2020-11-13T13:13:46Z")

</div>

@Phil could you help with this?

---

<div class="post-metadata">

**Author:** ![Levi](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/levi/32/24_2.png) [@Levi](https://community.prismic.io/u/Levi)\
**Post date:** [November 13, 2020, 3:02pm UTC](https://community.prismic.io/t/i-changed-the-uid-but-page-with-old-uid-is-still-active/2426/10 "2020-11-13T15:02:21Z")

</div>

Hi @kris & @marcellothearcane.

This behavior is happening because the UID field stores all previous values and allows you to query the document with these, even after the value has been changed. The reason it was designed this way was so that old link using the old UID value would still work (you wouldn't end up with broken links everywhere when you change the UID value).

So what we recommend doing is adding a check that compares the UID used to the current UID value. If it's an old UID value, then you redirect to the page using the new value.

In your particular case, the reason the old UID value works is indeed because you have `fallback` set to true. What I've done in my Next.js websites is add a useEffect to check if the UID value is out-of-date. Here is a simple example page that does this:

```auto
import React, { useEffect } from 'react'
import { useRouter } from 'next/router'
import Prismic from 'prismic-javascript'
import Custom404 from '../404'
import linkResolver from '../../utils/linkResolver'

export default function Page({ document, uid }) {
  const router = useRouter()
  if (router.isFallback) {
    return <h1>Loading...</h1>
  }

  if (!document) {
    return <Custom404 />
  }

  useEffect(() => {
    if (document.uid !== uid) {
      const forwardUrl = linkResolver(document)
      router.replace(forwardUrl)
    }
  }, [document])

  return (
    <div>
      ...your page content
    </div> 
  )
}

export async function getStaticPaths() {
  // getStaticPaths code
}

export async function getStaticProps({ params }) {
  const document = await Prismic.client('https://your-repo-name.cdn.prismic.io/api/v2')
    .getByUID('page', params.uid)

  return {
    props: { document, uid: params.uid },
  }
}

```

Give that a try and let me know if it solves your issue for you 😀

---

<div class="post-metadata">

**Author:** ![kris](https://avatars.discourse-cdn.com/v4/letter/k/82dd89/32.png) [@kris](https://community.prismic.io/u/kris)\
**Post date:** [November 14, 2020, 12:03am UTC](https://community.prismic.io/t/i-changed-the-uid-but-page-with-old-uid-is-still-active/2426/13 "2020-11-14T00:03:31Z")

</div>

This is exactly what I needed @Levi - I changed a bit of the code to accommodate for client's needs and I got it working!

Thank you and the whole Prismic team to being awesome as always.

PS: I think an article in the docs regarding this will be extremely helpful for future folks who will struggle with this

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/system/32/1746_2.png) [@system](https://community.prismic.io/u/system)\
**Post date:** [November 15, 2020, 12:03am UTC](https://community.prismic.io/t/i-changed-the-uid-but-page-with-old-uid-is-still-active/2426/14 "2020-11-15T00:03:33Z")

</div>

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/system/32/1746_2.png) [@system](https://community.prismic.io/u/system)\
**Post date:** [December 9, 2021, 5:13pm UTC](https://community.prismic.io/t/i-changed-the-uid-but-page-with-old-uid-is-still-active/2426/15 "2021-12-09T17:13:21Z")

</div>


