<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Marvelous Afolabi</title>
    <description>The latest articles on DEV Community by Marvelous Afolabi (@marvelousy20).</description>
    <link>https://dev.to/marvelousy20</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1073536%2Fde7bf656-2e9f-4b24-9f4d-b1ab51cf890d.PNG</url>
      <title>DEV Community: Marvelous Afolabi</title>
      <link>https://dev.to/marvelousy20</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/marvelousy20"/>
    <language>en</language>
    <item>
      <title>Exploring Dynamic routing in Nextjs 13</title>
      <dc:creator>Marvelous Afolabi</dc:creator>
      <pubDate>Wed, 02 Aug 2023 11:09:12 +0000</pubDate>
      <link>https://dev.to/marvelousy20/exploring-dynamic-routing-in-nextjs-13-57im</link>
      <guid>https://dev.to/marvelousy20/exploring-dynamic-routing-in-nextjs-13-57im</guid>
      <description>&lt;p&gt;As developers, we often encounter the need to build web applications that adapt to changing data and user interactions. &lt;a href="https://nextjs.org/"&gt;Nextjs&lt;/a&gt;, a powerful React framework has introduced exciting upadates in its latest release, version 13, that further enhances our ability to create dynamic and flexible web experiences.&lt;br&gt;
One of the things I constantly find myself doing as a frontend developer is displaying content based on a user interaction. &lt;br&gt;
In this article, we will delve into the concept of dynamic routing and how it empowers us to create customizable web pages. &lt;/p&gt;

&lt;p&gt;Let's get started.&lt;/p&gt;

&lt;p&gt;We are going to have a simple profiles data. This is an array, which contains two objects.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C67r40Lb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zf8i4irhi5n9x0yhds40.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C67r40Lb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zf8i4irhi5n9x0yhds40.png" alt="Image description" width="800" height="581"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we will create a straightforward interface that displays the two profile names obtained from the data array. Alongside each name, we will provide a clickable link that allows the user to access more information about the selected profile.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IejbPKmD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p1xaeqxxt37dfipxnpfz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IejbPKmD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p1xaeqxxt37dfipxnpfz.png" alt="Image description" width="800" height="510"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lastly, we will generate a dynamic segment by enclosing the folder's name in square brackets, such as [folderName]. This technique allows us to create flexible routes based on dynamic parameters like [id] or [slug]. In our case, we will create a folder named [slug] within the app directory. Within this folder, we will create a file called page.tsx and insert the provided code snippet.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HyTq3roZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s13j4fckn11yo43dom39.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HyTq3roZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s13j4fckn11yo43dom39.png" alt="Image description" width="800" height="559"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, we applied the filter method to the data by comparing the profile names to the value of params.slug. If there is a match, the corresponding array is returned. Subsequently, we use destructuring to extract the necessary data from the array and update our user interface accordingly.&lt;br&gt;
We will now notice that once the link is clicked, the UI changes to display the description of the corresponding profile being clicked.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note: This assumes you want to route to localhost:3000/jeff and localhost:3000/peter&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To route to &lt;a href="http://localhost:3000/profile/john"&gt;http://localhost:3000/profile/john&lt;/a&gt;, you've to create the [slug] folder inside a profile a directory. I recommend taking a look at the official doc &lt;a href="https://nextjs.org/docs/app/building-your-application/routing/dynamic-routes"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope this helps!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
