# Dynamic routing using nextjs not working

**URL:** <https://forum.builder.io/t/dynamic-routing-using-nextjs-not-working/3044>\
**Category:** Technical Questions\
**Created:** [January 5, 2023, 12:50pm UTC](https://forum.builder.io/t/dynamic-routing-using-nextjs-not-working/3044 "2023-01-05T12:50:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![samnagaraj](https://avatars.discourse-cdn.com/v4/letter/s/87869e/32.png) [@samnagaraj](https://forum.builder.io/u/samnagaraj)\
**Post date:** [January 5, 2023, 12:50pm UTC](https://forum.builder.io/t/dynamic-routing-using-nextjs-not-working/3044/1 "2023-01-05T12:50:13Z")

</div>

**Builder content link**

> **[Builder.io: Visual Development Platform](https://builder.io/content/c647469429f84dfe97152b37e709bea3)**
>
> Builder is an AI-Powered Visual Development Platform that helps teams generate, iterate, and optimize web and mobile experiences in seconds instead of sprints.

**What are you trying to accomplish**  
We are trying create dynamic content page with [builder.io](http://builder.io) and nextjs.

Getting the following error whenever we are trying to creating dynamic routing in nextjs:

# Server Error

Error: The provided path `/home` does not match the page: `/factsheets/[name]`.

This error happened while generating the page. Any console logs will be displayed in the terminal window.

nextjs folder: pages/factsheets/[name].tsx  
eg url: {url}/factsheets/abcd (with dynamic routing starts with /factsheets)

**Screenshots or video link**

 ![image](https://us1.discourse-cdn.com/flex020/uploads/builder/original/2X/c/ce4d8e81ed7b751b0409eb28b19519de27a2ffd0.png)

**Code stack you are integrating Builder with**  
NextJS

**Reproducible code example**  
import { useRouter } from ‘next/router’;  
import DefaultErrorPage from ‘next/error’;  
import Head from ‘next/head’;  
import React from ‘react’;  
import { BuilderComponent, builder, useIsPreviewing, Builder } from ‘@builder.io/react’;  
import ‘@builder.io/widgets’;  
import ‘../../components’;

export async function getStaticProps( { params }:any ) {  
// Fetch the first page from Builder that matches the current URL.  
// Use the `userAttributes` field for targeting content.  
// For more, see [Targeting content](https://www.builder.io/c/docs/targeting-with-builder)  
const page = await builder  
.get(‘page’, {  
userAttributes: {  
urlPath: ‘/’ + (params?.item?.join(‘/’) || ‘’),  
},  
})  
.toPromise();

return {  
props: {  
page: page || null,  
},  
revalidate: 5,  
};  
}

export async function getStaticPaths() {  
// Fetch all published pages for the current model.  
// Using the `fields` option will limit the size of the response  
// and only return the `data.url` field from the matching pages.  
const pages = await builder.getAll(‘page’, {  
fields: ‘data.url’, // only request the `data.url` field  
options: { noTargeting: true },  
limit: 0,  
});  
console.log(pages);  
return {  
paths: pages.map(page =\> `${page.data?.url}`),  
fallback: true,  
};  
}

export default function Page( { page }:any ) {  
const router = useRouter();  
// This flag indicates if you are viewing the page in the Builder editor.  
const isPreviewing = useIsPreviewing();

if (router.isFallback) {  
return

# Loading…
;  
}

// Add your error page here to return if there are no matching  
// content entries published in Builder.  
if (!page && !isPreviewing) {  
return ;  
}

return (  
\<\>  
  
{/\* Add any relevant SEO metadata or open graph tags here \*/}  
{page?.data.title}

```
  </Head>
  {/* Render the Builder page */}
  <BuilderComponent model="page" content={page} />
</>

```

);  
}

---

<div class="post-metadata">

**Author:** ![manish-sharma](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@manish-sharma](https://forum.builder.io/u/manish-sharma)\
**Post date:** [January 6, 2023, 1:52pm UTC](https://forum.builder.io/t/dynamic-routing-using-nextjs-not-working/3044/2 "2023-01-06T13:52:41Z")

</div>

Hi @samnagaraj ,

Welcome to the [builder.io](http://builder.io) forum!

We are not quite able to reproduce this possible error but you can try a couple of things

1. Using the `Is` filter instead of `Starts with`.

2. When using `params?.item`, we were also getting a similar error and it wasn’t working, so you can also try using `params.?page`

```auto
const page = await builder
.get(‘page’, {
  userAttributes: {
    urlPath: ‘/’ + (params?.page?.join(‘/’) || ‘’),
  },
})

```

 ![Screenshot 2023-01-06 at 7.17.48 PM](https://us1.discourse-cdn.com/flex020/uploads/builder/original/2X/0/0cb8d633a67ce5ef34b512e1357367ff3fca28d4.jpeg)

 ![Screenshot 2023-01-06 at 7.21.13 PM](https://us1.discourse-cdn.com/flex020/uploads/builder/original/2X/3/30ea0fcc0ea0fe65b48206a91588ef9f267d3803.png)
