# Can't get querying other types in a sub directory to work

**URL:** <https://community.prismic.io/t/cant-get-querying-other-types-in-a-sub-directory-to-work/5630>\
**Category:** Developing with Prismic\
**Tags:** slice-machine\
**Created:** [June 4, 2021, 10:03pm UTC](https://community.prismic.io/t/cant-get-querying-other-types-in-a-sub-directory-to-work/5630 "2021-06-04T22:03:06Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevin](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/kevin/32/2184_2.png) [@kevin](https://community.prismic.io/u/kevin)\
**Post date:** [June 4, 2021, 10:03pm UTC](https://community.prismic.io/t/cant-get-querying-other-types-in-a-sub-directory-to-work/5630/1 "2021-06-04T22:03:06Z")

</div>

We're using Slice Machine to build a new website with Next.js. I'm currently stuck trying to get our blog posts to render out in the next app. Here are the contents of my pages directory:

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/prismic/original/2X/0/0e45b7168391ec4246bdfb88a57d9f3b661edc1d.png)  
Everything works as expected, with the exception of `pages/blog/[uid].tsx`. Here are the contents of that file:

```auto
import SliceZone from 'next-slicezone';
import { useGetStaticProps, useGetStaticPaths } from 'next-slicezone/hooks';
import { Client } from '../../prismic-configuration';
import Layout from '../../components/Layout';

import resolver from '../../sm-resolver';

type Props = any;

export default function BlogPost(props: Props) {
  console.log({ props });
  return (
    <Layout globals={props.globals}>
      <h1>Blog template</h1>
      <SliceZone {...props} resolver={resolver} />
    </Layout>
  );
}
// Fetch content from prismic
// eslint-disable-next-line react-hooks/rules-of-hooks
export const getStaticProps = useGetStaticProps({
  client: Client(),
  type: 'blog',
  apiParams({ params }: any) {
    return {
      uid: params.uid,
    };
  },
});

// eslint-disable-next-line react-hooks/rules-of-hooks
export const getStaticPaths = useGetStaticPaths({
  client: Client(),
  formatPath: (prismicDocument: any) => {
    return {
      params: {
        uid: prismicDocument.uid,
      },
    };
  },
});

```

When I try to access [http://localhost:3000/blog/test-blog-post](http://localhost:3000/blog/test-blog-post) I am presented with the following:

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/prismic/original/2X/d/da3ca1ba822dabeac27b4d3d0ba488122d428414.png)

In prismic I have a repeatable type of "Blog" with the api id of "blog".

---

<div class="post-metadata">

**Author:** ![Pau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/pau/32/5422_2.png) [@Pau](https://community.prismic.io/u/Pau)\
**Post date:** [June 7, 2021, 4:15pm UTC](https://community.prismic.io/t/cant-get-querying-other-types-in-a-sub-directory-to-work/5630/2 "2021-06-07T16:15:55Z")

</div>

Hello @kevin, welcome to the community!

I'm wondering if the `[uid].js` file is creating a conflict between the routes. Are you creating a default export for that one?

Could you show me an example of how this file looks like?

---

<div class="post-metadata">

**Author:** ![kevin](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/kevin/32/2184_2.png) [@kevin](https://community.prismic.io/u/kevin)\
**Post date:** [June 7, 2021, 4:33pm UTC](https://community.prismic.io/t/cant-get-querying-other-types-in-a-sub-directory-to-work/5630/4 "2021-06-07T16:33:46Z")

</div>

[uid].js looks like this:

```auto
import SliceZone from 'next-slicezone';
import { useGetStaticProps, useGetStaticPaths } from 'next-slicezone/hooks';
import { Client } from '../prismic-configuration';
import Layout from '../components/Layout';

import resolver from '../sm-resolver';

const Page = (props) => {
  return (
    <Layout globals={props.globals}>
      <SliceZone {...props} resolver={resolver} />
    </Layout>
  );
};
// Fetch content from prismic
// eslint-disable-next-line react-hooks/rules-of-hooks
export const getStaticProps = useGetStaticProps({
  client: Client(),
  uid: ({ params }) => params.uid,
});

// eslint-disable-next-line react-hooks/rules-of-hooks
export const getStaticPaths = useGetStaticPaths({
  client: Client(),
  type: 'page',
  fallback: process.env.NODE_ENV === 'development',
  formatPath: (prismicDocument) => {
    return {
      params: {
        uid: prismicDocument.uid,
      },
    };
  },
});

export default Page;

```

---

<div class="post-metadata">

**Author:** ![Pau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/pau/32/5422_2.png) [@Pau](https://community.prismic.io/u/Pau)\
**Post date:** [June 7, 2021, 7:08pm UTC](https://community.prismic.io/t/cant-get-querying-other-types-in-a-sub-directory-to-work/5630/5 "2021-06-07T19:08:20Z")

</div>

Ok, So I think the problem comes from the Lifecycle hooks of `[uid].js` They are using the old syntax to retrieve the uid. `useGetStaticProps` isn't using `apiParams`.

You're using it correctly in `/blog/[uid].tsx` tho. Look at this document where we explain how to query repeatable documents:

> **[How to Query the API with Next.js](https://prismic.io/docs/technologies/query-api-nextjs#query-repeatable-types-by-uid)**
>
> To work with your content in Next, you must first query it from the Prismic API. On this page, you'll learn how to do a Prismic API query in your Next project.

The routing for your pages is:

- For type Page: `/uid`
- For the Blog type: `/blog/uid` for the Blog types

Is that correct?

---

<div class="post-metadata">

**Author:** ![kevin](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/kevin/32/2184_2.png) [@kevin](https://community.prismic.io/u/kevin)\
**Post date:** [June 7, 2021, 7:39pm UTC](https://community.prismic.io/t/cant-get-querying-other-types-in-a-sub-directory-to-work/5630/6 "2021-06-07T19:39:54Z")

</div>

Yes that's what I'm trying to do. Thanks, I'll make sure we're using the right approach in both places.

---

<div class="post-metadata">

**Author:** ![kevin](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/kevin/32/2184_2.png) [@kevin](https://community.prismic.io/u/kevin)\
**Post date:** [June 7, 2021, 7:52pm UTC](https://community.prismic.io/t/cant-get-querying-other-types-in-a-sub-directory-to-work/5630/7 "2021-06-07T19:52:11Z")

</div>

OK I updated to look like that, now I can get to the blog page but it's telling me that my slice zone is empty when it is not. For the props on `blog/uid`, I'm getting an empty array of slices, and an error message "Error: Unable to encode null of type object", and a null UID prop.

---

<div class="post-metadata">

**Author:** ![kevin](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/kevin/32/2184_2.png) [@kevin](https://community.prismic.io/u/kevin)\
**Post date:** [June 7, 2021, 7:56pm UTC](https://community.prismic.io/t/cant-get-querying-other-types-in-a-sub-directory-to-work/5630/8 "2021-06-07T19:56:24Z")

</div>

Actually, after updating the hooks I am no longer getting slices on my normal pages either. I have ensured that all of my prismic-related NPM packages are completely up to date.

---

<div class="post-metadata">

**Author:** ![kevin](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/kevin/32/2184_2.png) [@kevin](https://community.prismic.io/u/kevin)\
**Post date:** [June 7, 2021, 7:59pm UTC](https://community.prismic.io/t/cant-get-querying-other-types-in-a-sub-directory-to-work/5630/9 "2021-06-07T19:59:16Z")

</div>

The following code made my blog route work (working code on the right, this is a diff of what I changed):

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/prismic/original/2X/8/8dd50705acb41580d438e9f64133c2e0d6393c54.png)

---

<div class="post-metadata">

**Author:** ![kevin](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/kevin/32/2184_2.png) [@kevin](https://community.prismic.io/u/kevin)\
**Post date:** [June 8, 2021, 3:50pm UTC](https://community.prismic.io/t/cant-get-querying-other-types-in-a-sub-directory-to-work/5630/10 "2021-06-08T15:50:57Z")

</div>

@Pau it seems that the docs are out of sync with the latest version of the available packages, which led to my confusion.

---

<div class="post-metadata">

**Author:** ![Pau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/pau/32/5422_2.png) [@Pau](https://community.prismic.io/u/Pau)\
**Post date:** [June 8, 2021, 7:06pm UTC](https://community.prismic.io/t/cant-get-querying-other-types-in-a-sub-directory-to-work/5630/11 "2021-06-08T19:06:18Z")

</div>

Hey @kevin, thanks for sharing all the troubleshooting details of your project.  
Could you please point out to me where did you saw an outdated section of the documentation?  
It'll help us know if something in the docs isn't clear enough; feedback is always welcome!

---

<div class="post-metadata">

**Author:** ![kevin](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/kevin/32/2184_2.png) [@kevin](https://community.prismic.io/u/kevin)\
**Post date:** [June 8, 2021, 9:30pm UTC](https://community.prismic.io/t/cant-get-querying-other-types-in-a-sub-directory-to-work/5630/12 "2021-06-08T21:30:45Z")

</div>

The code that you recommended I follow from the docs is what broke my pages. Going back to what I was originally using fixed the issues. Here's my whole package.json so that you can see which versions I am using.

```auto
{
  "name": "marketing-next",
  "version": "1.0.0",
  "scripts": {
    "dev": "next",
    "build": "next build",
    "start": "next start",
    "type-check": "tsc --project tsconfig.json --pretty --noEmit",
    "lint": "eslint --ext js,jsx,ts,tsx --fix --cache",
    "slicemachine": "start-slicemachine --port 9999",
    "storybook": "start-storybook -p 8888",
    "build-storybook": "build-storybook",
    "everything": "concurrently \"yarn dev\" \"yarn slicemachine\" \"yarn storybook\"",
    "prepare": "husky install"
  },
  "dependencies": {
    "@aaronhayes/react-use-hubspot-form": "^1.2.5",
    "@brainhubeu/react-carousel": "^2.0.4",
    "@prismicio/client": "^5.0.0",
    "@storybook/react": "^6.2.9",
    "@svgr/webpack": "^5.5.0",
    "next": "10.2.0",
    "next-slicezone": "^0.0.15",
    "next-transpile-modules": "^7.0.0",
    "papaparse": "^5.3.1",
    "prismic-javascript": "^3.0.2",
    "prismic-reactjs": "^1.3.4",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-select-search": "^3.0.7",
    "react-table": "^7.7.0",
    "sanitize.css": "^12.0.1",
    "styled-components": "^5.3.0",
    "theme-ui": "^0.8.1"
  },
  "devDependencies": {
    "@types/brainhubeu__react-carousel": "^2.0.2",
    "@types/node": "^15.0.2",
    "@types/papaparse": "^5.2.5",
    "@types/react": "^17.0.5",
    "@types/react-dom": "^17.0.3",
    "@types/react-table": "^7.7.1",
    "@types/styled-components": "^5.1.9",
    "@typescript-eslint/eslint-plugin": "^4.26.0",
    "@typescript-eslint/parser": "^4.26.0",
    "babel-loader": "^8.2.2",
    "babel-plugin-react-require": "^3.1.3",
    "babel-plugin-styled-components": "^1.12.0",
    "concurrently": "^6.2.0",
    "eslint": "^7.27.0",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-jsx-a11y": "^6.4.1",
    "eslint-plugin-prettier": "^3.4.0",
    "eslint-plugin-react": "^7.24.0",
    "eslint-plugin-react-hooks": "^4.2.0",
    "husky": "^6.0.0",
    "lint-staged": "^11.0.0",
    "prettier": "^2.3.0",
    "prismic-cli": "^3.8.13",
    "slice-machine-ui": "^0.0.46",
    "typescript": "4.2.4"
  },
  "license": "MIT"
}

```

---

<div class="post-metadata">

**Author:** ![Pau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/pau/32/5422_2.png) [@Pau](https://community.prismic.io/u/Pau)\
**Post date:** [June 9, 2021, 7:47pm UTC](https://community.prismic.io/t/cant-get-querying-other-types-in-a-sub-directory-to-work/5630/13 "2021-06-09T19:47:50Z")

</div>

Ok, I see; thanks for the info.  
We're constantly making updates to the documentation, so all the feedback is more than welcome

---

<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:** [June 10, 2021, 7:48pm UTC](https://community.prismic.io/t/cant-get-querying-other-types-in-a-sub-directory-to-work/5630/14 "2021-06-10T19:48:43Z")

</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, 6:06pm UTC](https://community.prismic.io/t/cant-get-querying-other-types-in-a-sub-directory-to-work/5630/15 "2021-12-09T18:06:36Z")

</div>


