Hey there,
A similar yet different issue with my code. I promise I have spent ages trying to figure this out before coming here. But alas no result. Hoping someone can help.
I've added a new content type of blog
I've then added this to my route resolver:
and here is the code that is throwing the error:
and lastly the error:
I do have a few blogs created as you can see here and they are published and live.
So I have no idea what the error is for or how to resolve. I can only think either my routes are wrong because I've misunderstood something or my code is wrong.
Hope some one can help me here.
Thanks
Hello @willbrettdesign,
Thanks for reaching out to us!
From what I can see, blog
is your Custom Type name and not your uid value; you can check your repository to see what your uid value is and use that in the URL on your browser like so /uid-value
, and you should get the right page.
Can you tell me what value you're pointing to on your browser?
Thanks,
Racheal.
Thanks @racheal.orukele ,
I'm try to load a page based on which blog tile is clicked. For example on my home page I have an array of blog tiles. Each has a UID value so when these are clicked it should open a new page using that UID.
image of blogs on homepage:
Image of url once one of those blog tiles is pressed
I'm pretty sure the URL is correct here as the blog I pressed' UID is = 1.
So I have no idea why it's throwing an error.
Hey @willbrettdesign,
Yeah, you're pointing to the correct UID value on the browser.
Can you share a code snippet of the code throwing this error?
You can send it via DM if you prefer.
Hey @racheal.orukele
Here is the entire code for the [uid].js page which I believe is throwing the code:
import { CreateClient, createClient } from "@prismicio/client"
const BlogPage = () => { //***Add the props to pass from the bottom of this file
return <></>
};
export default BlogPage;
export async function getServerSideProps(ctx) {
//create client to connect with prismic
const client = createClient();
//get links by UID
const blog = await client.getByUID('blog', ctx.params.uid, {
// fetchLinks:['blog.uid', 'blog.title', 'blog.content', 'blog.category', 'blog.timetoread', 'blog.blogimage, blog.author, author.authorname', 'author.avatar', 'blog.releasedate']
});
console.log(blog);
return{
//return the properties
props: {
//properties to pass
}
}
}
Hello @willbrettdesign,
You're importing createClient
from "@prismicio/client";
and not connecting the client to your Prismic API endpoint. To connect the client to your API, do this:
const client = createClient(sm.apiEndpoint);
Or you can import the client from import { createClient } from "../prismicio";
Let me know if this works.
Thanks,
Racheal.
Oh rookie error! I did this before and caught it, no idea how I managed it this time.
Thanks so much @racheal.orukele for your help here. Definitely should have caught this one myself but really pleased you were able to solve it!
I suppose it doesn't help that VSC autocompletes the createclient to the wrong one each time.
Thanks again!
1 Like
No worries, @willbrettdesign I'm glad everything works fine. Let us know if you have any other questions.
1 Like