<?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: Emmyojile</title>
    <description>The latest articles on DEV Community by Emmyojile (@emmyojile).</description>
    <link>https://dev.to/emmyojile</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%2F1019046%2Fce93ef47-4ab8-48f2-8c24-181da1b4a973.jpg</url>
      <title>DEV Community: Emmyojile</title>
      <link>https://dev.to/emmyojile</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/emmyojile"/>
    <language>en</language>
    <item>
      <title>From Chaos to Clarity: How Next.js Streamlines Routing</title>
      <dc:creator>Emmyojile</dc:creator>
      <pubDate>Sat, 10 Feb 2024 20:10:44 +0000</pubDate>
      <link>https://dev.to/emmyojile/from-chaos-to-clarity-how-nextjs-streamlines-routing-4mka</link>
      <guid>https://dev.to/emmyojile/from-chaos-to-clarity-how-nextjs-streamlines-routing-4mka</guid>
      <description>&lt;p&gt;Remember grappling with react-router-dom in your React apps? Manually defining routes, configuring components, and wrangling nested structures was a headache. Well, fear not! Next.js introduces a game-changer: the app folder. Ditch the complexity and embrace an intuitive, organized file-based system for effortless routing.&lt;br&gt;
If you are seeing this, it is assumed you have a basic knowledge of react and it's envrions. Aswell as the use of react-router-dom library which is a tool used to route between various pages in your application.&lt;br&gt;
Before we go any further let's compare the two and see why Next.js makes everything easier:&lt;br&gt;
&lt;strong&gt;The Old Way: react-router-dom&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Configuration heavy: You needed to define routes in a separate file, manually mapping URLs to components.&lt;/li&gt;
&lt;li&gt;Potential confusion: Nested routes and dynamic parameters could lead to complex configurations and debugging challenges.&lt;/li&gt;
&lt;li&gt;Separate components: Your page components and routing logic lived in different files, adding an extra layer of complexity.
Below is an image of how using react-router-dom library could could look like&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxmjj8hv4aa1cfwevmrq2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxmjj8hv4aa1cfwevmrq2.png" alt="Image description" width="800" height="601"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The New Way: Next.js app Folder&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simplicity is king: Each file within the app folder represents a unique page. No more complex configurations – Next.js magically detects and renders them. Just name a file page.js or page.ts, and boom! You have a new page.&lt;/li&gt;
&lt;li&gt;Intuitive and maintainable: The file structure directly mirrors your website's layout, making navigation and code management a breeze.&lt;/li&gt;
&lt;li&gt;Components and routes combined: Each page file holds both your component and its corresponding route, leading to cleaner and more cohesive code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Below is an image showing the typical folder structure of nextjs folder structure&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fovjm7gdesh48bt0cbvpd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fovjm7gdesh48bt0cbvpd.png" alt="Image description" width="774" height="626"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see in the image, different subfolders like &lt;code&gt;about&lt;/code&gt;, &lt;code&gt;blog&lt;/code&gt;, &lt;code&gt;login&lt;/code&gt;, and &lt;code&gt;register&lt;/code&gt; exist within the app folder. Each folder contains a file named &lt;code&gt;page.js&lt;/code&gt; or &lt;code&gt;page.ts&lt;/code&gt; representing its content. Simply by visiting the URL corresponding to the folder name (e.g., &lt;code&gt;/about&lt;/code&gt;, &lt;code&gt;/blog&lt;/code&gt;, etc.), you can access the content of each page, making navigation incredibly intuitive.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa4daoaawrfgms5gsupr3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa4daoaawrfgms5gsupr3.png" alt="Image description" width="734" height="416"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Voilà! As you can see in the image below, simply starting your app and visiting the URL corresponding to the folder name (e.g., &lt;code&gt;/login&lt;/code&gt;) directly links you to its content. In this example, we're accessing the login page by visiting &lt;code&gt;/login&lt;/code&gt;, showcasing the intuitive file-based routing of Next.js.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Remember those days grappling with react-router-dom? I certainly do! Manually defining routes, wrangling nested structures, and debugging complex configurations – it was a constant headache. But then I discovered Next.js and its magical app folder. Let me tell you, it was a game-changer!&lt;/p&gt;

&lt;p&gt;Since using Next.js, I haven't even considered going back to traditional React routing. The intuitive file-based system is incredibly simple and efficient. Building and managing pages is a breeze, resulting in fantastic project organization. Gone are the days of separate configurations and confusing logic – with Next.js, everything just clicks!&lt;/p&gt;

&lt;p&gt;But you don't just have to take my word for it. Share your own experiences with react-router-dom and Next.js in the comments below! What challenges did you face, and how has Next.js simplified your routing process? Let's build a community around simplifying development by embracing Next.js together. Feel free to ask questions in the comments to continue the conversation.&lt;/p&gt;

&lt;p&gt;Join the growing community of developers who've embraced Next.js for effortless routing! Start exploring Next.js documentation (&lt;a href="https://nextjs.org/docs/getting-started/installation"&gt;https://nextjs.org/docs/getting-started/installation&lt;/a&gt;) and jump into the world of effortless routing today!&lt;/p&gt;

</description>
      <category>reactrouterdom</category>
      <category>nextjsappfolder</category>
      <category>nextjs</category>
    </item>
  </channel>
</rss>
