<?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: OscarDOM</title>
    <description>The latest articles on DEV Community by OscarDOM (@oscardom).</description>
    <link>https://dev.to/oscardom</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%2F80591%2Fd4481e99-7bab-4498-8f5d-54bca3766b45.png</url>
      <title>DEV Community: OscarDOM</title>
      <link>https://dev.to/oscardom</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/oscardom"/>
    <language>en</language>
    <item>
      <title>How to use 'Nested Layouts' without 'Nested URLs' in Remix</title>
      <dc:creator>OscarDOM</dc:creator>
      <pubDate>Sat, 12 Aug 2023 16:30:44 +0000</pubDate>
      <link>https://dev.to/oscardom/how-to-use-nested-layouts-without-nested-urls-in-remix-1i7f</link>
      <guid>https://dev.to/oscardom/how-to-use-nested-layouts-without-nested-urls-in-remix-1i7f</guid>
      <description>&lt;p&gt;In today's ever-evolving web development sphere, we constantly look for ways to optimize and make our applications more maintainable. If you've been using Remix, you might have wondered, "How can I share layouts among different routes without adding to the URL path?" Well, I've got good news for you. I recently refactored my Remix app to do just that. In this blog post, I'll share a strategy to achieve nested layouts without the nested URLs, also known as "Pathless Routes".&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem:
&lt;/h2&gt;

&lt;p&gt;In my previous setup, I rendered a &lt;code&gt;&amp;lt;Header&amp;gt;&lt;/code&gt; component directly in the &lt;code&gt;root.tsx&lt;/code&gt;. However, as my app evolved, this approach made it harder to manage, especially when dealing with login/logout logic. This complexity made updates challenging and increased the risk of bugs..&lt;/p&gt;

&lt;h2&gt;
  
  
  The Solution: Pathless Routes
&lt;/h2&gt;

&lt;p&gt;Remix &lt;a href="https://remix.run/docs/en/1.19.3/file-conventions/route-files-v2#nested-urls-without-layout-nesting"&gt;offers a fascinating solution&lt;/a&gt; to this: the _&lt;em&gt;leading` underscore&lt;/em&gt;. With this, you can group routes under a common layout without adding any extra segments to the URL. It’s like giving these routes a shared home without changing their address!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;⚠️ The solution I'm sharing is based on &lt;a href="https://remix.run/docs/en/1.19.3/file-conventions/route-files-v2"&gt;&lt;strong&gt;Remix v2&lt;/strong&gt; Route File Naming&lt;/a&gt;. Remix v1 covers this use-case but the way it's done is different. You can read more about it in &lt;a href="https://remix.run/docs/en/1.19.3/file-conventions/routes-files#pathless-layout-routes"&gt;Remix's docs page&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here's a basic structure before refactoring:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
app/&lt;br&gt;
├── routes/&lt;br&gt;
│   ├── login.tsx&lt;br&gt;
│   ├── register.tsx&lt;br&gt;
│   ├── _index.tsx&lt;br&gt;
│   ├── concerts.$city.tsx&lt;br&gt;
│   └── concerts.tsx&lt;br&gt;
└── root.tsx&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Breaking it down (before refactoring):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;URL &lt;code&gt;/&lt;/code&gt; would render &lt;code&gt;/_index.tsx&lt;/code&gt; with the layout of root.tsx.&lt;/li&gt;
&lt;li&gt;URL &lt;code&gt;/login&lt;/code&gt; would directly match &lt;code&gt;login.tsx&lt;/code&gt; and use the layout from &lt;code&gt;root.tsx&lt;/code&gt; since there isn't a specific layout just for it.&lt;/li&gt;
&lt;li&gt;Similarly, &lt;code&gt;/register&lt;/code&gt; directly corresponds to &lt;code&gt;register.tsx&lt;/code&gt;, using the &lt;code&gt;root.tsx&lt;/code&gt; layout as well.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the original structure, without the leading underscore (Pathless Routes) approach, each route directly reflects the filename, and all routes lean on the &lt;code&gt;root.tsx&lt;/code&gt; for the layout unless specified otherwise.&lt;/p&gt;

&lt;p&gt;And here's how the file tree looks like after applying pathless routes:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
app/&lt;br&gt;
├── routes/&lt;br&gt;
│   ├── _auth.login.tsx&lt;br&gt;
│   ├── _auth.register.tsx&lt;br&gt;
│   ├── _auth.tsx&lt;br&gt;
│   ├── _index.tsx&lt;br&gt;
│   ├── concerts.$city.tsx&lt;br&gt;
│   └── concerts.tsx&lt;br&gt;
└── root.tsx&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Breaking it down (after refactoring with pathless routes):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;URL &lt;code&gt;/&lt;/code&gt; would render &lt;code&gt;_index.tsx&lt;/code&gt; with the layout of &lt;code&gt;root.tsx&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;URL &lt;code&gt;/login&lt;/code&gt; would match &lt;code&gt;_auth.login.tsx&lt;/code&gt; and take its layout from &lt;code&gt;_auth.tsx&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Similarly, &lt;code&gt;/register&lt;/code&gt; maps to &lt;code&gt;_auth.register.tsx&lt;/code&gt;, also using &lt;code&gt;_auth.tsx&lt;/code&gt; as its layout.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By using a _&lt;em&gt;leading underscore&lt;/em&gt;, you essentially hide the filename from the URL, giving you the ability to share a layout amongst different routes seamlessly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Decoupling Logic&lt;/strong&gt;: By moving shared components like &lt;code&gt;&amp;lt;Header&amp;gt;&lt;/code&gt; out of &lt;code&gt;root.tsx&lt;/code&gt;, I can keep the login/logout logic isolated, making the codebase cleaner and easier to maintain. Now my &lt;code&gt;root.tsx&lt;/code&gt; &lt;code&gt;loader()&lt;/code&gt; function is simpler and focused on high-level layout.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Improved Organization&lt;/strong&gt;: Grouping related routes under a shared layout improves the organization of your project, making it more intuitive for developers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flexible URLs&lt;/strong&gt;: With pathless routes, you get to dictate the URL structure without being tied down by your file or folder naming conventions.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Final Thoughts:
&lt;/h2&gt;

&lt;p&gt;Adopting this pattern has significantly improved the structure and maintainability of my Remix app. The _&lt;em&gt;leading underscore&lt;/em&gt; might seem like a small, inconsequential change, but its impact on the project's architecture is substantial.&lt;/p&gt;

&lt;p&gt;If you've been struggling with managing shared layouts in Remix or just looking for ways to improve your app's structure, give this method a try. Remember, in the world of web development, it's often the small tweaks that lead to the most significant improvements.&lt;/p&gt;

&lt;p&gt;Happy coding 🤓!&lt;/p&gt;




&lt;p&gt;This post &lt;a href="https://www.oscardom.dev/blog/remix/nested-layouts-without-nested-urls"&gt;was initially published on my blog&lt;/a&gt;. Come by and check other publications I have at &lt;a href="https://oscardom.dev"&gt;https://oscardom.dev&lt;/a&gt;  or say hi to me on Twitter: &lt;a href="https://twitter.com/oscard0m_"&gt;@oscard0m_&lt;/a&gt;&lt;/p&gt;

</description>
      <category>remix</category>
      <category>react</category>
      <category>routing</category>
    </item>
    <item>
      <title>Faster and colourful Command-Line tools 🌈⚡</title>
      <dc:creator>OscarDOM</dc:creator>
      <pubDate>Sun, 25 Sep 2022 17:52:16 +0000</pubDate>
      <link>https://dev.to/oscardom/faster-and-colorful-command-line-tools-4199</link>
      <guid>https://dev.to/oscardom/faster-and-colorful-command-line-tools-4199</guid>
      <description>&lt;p&gt;Today is Sunday, and I decided I wanted to look into some of the Command-Line tools written in Rust out there. Some of them have a lot of stars ⭐ on GitHub, so I have a good feeling these will be tools I will enjoy as a user and improve my productivity.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.rust-lang.org/"&gt;Rust&lt;/a&gt; is a programming language &lt;a href="https://dev.to/previously/2022-08"&gt;I want to get involved with&lt;/a&gt;. I came up with the idea of integrating some Command Line tools written in Rust in my day-to-day could be an excellent opportunity to get in touch with them as a user and, from there, maybe get involved in opening a new issue or drafting a Pull Request. Why not!&lt;/p&gt;

&lt;p&gt;Here's the list of Command-Line tools I installed today on my personal computer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/sharkdp/bat"&gt;&lt;code&gt;bat&lt;/code&gt;&lt;/a&gt;: A cat(1) clone with wings. It offers &lt;em&gt;Syntax highlighting&lt;/em&gt; and &lt;em&gt;Git integration&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/imsnif/bandwhich"&gt;&lt;code&gt;bandwhich&lt;/code&gt;&lt;/a&gt;: A terminal bandwidth utilization tool. This CLI utility displays current network utilization by process, connection and remote IP/hostname.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/ClementTsang/bottom"&gt;&lt;code&gt;bottom&lt;/code&gt;&lt;/a&gt;: A customizable cross-platform graphical process/system monitor for the terminal.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/dandavison/delta"&gt;&lt;code&gt;delta&lt;/code&gt;&lt;/a&gt;: A syntax-highlighting pager for git, diff, and grep output.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/bootandy/dust"&gt;&lt;code&gt;dust&lt;/code&gt;&lt;/a&gt;: A more intuitive version of du in Rust.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/ogham/exa"&gt;&lt;code&gt;exa&lt;/code&gt;&lt;/a&gt;: A modern replacement for &lt;code&gt;ls&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/sharkdp/fd"&gt;&lt;code&gt;fd&lt;/code&gt;&lt;/a&gt;: A simple, fast and user-friendly alternative to 'find'.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/sharkdp/hyperfine"&gt;&lt;code&gt;hyperfine&lt;/code&gt;&lt;/a&gt;: A command-line benchmarking tool.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/dalance/procs"&gt;&lt;code&gt;prox&lt;/code&gt;&lt;/a&gt;: A modern replacement for &lt;code&gt;ps&lt;/code&gt; written in Rust.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/BurntSushi/ripgrep"&gt;&lt;code&gt;ripgrep&lt;/code&gt;&lt;/a&gt;: &lt;code&gt;ripgrep&lt;/code&gt; recursively searches directories for a RegEx pattern while respecting your &lt;code&gt;.gitignore&lt;/code&gt;. Similar to popular search tools like &lt;code&gt;The Silver Searcher&lt;/code&gt;, &lt;code&gt;ack&lt;/code&gt; and &lt;code&gt;grep&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/chmln/sd"&gt;&lt;code&gt;sd&lt;/code&gt;&lt;/a&gt;: Intuitive find &amp;amp; replace CLI (&lt;code&gt;sed&lt;/code&gt; alternative).&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/dbrgn/tealdeer"&gt;&lt;code&gt;tealdeer&lt;/code&gt;&lt;/a&gt;: A very fast implementation of &lt;a href="https://github.com/tldr-pages/tldr"&gt;&lt;code&gt;tldr&lt;/code&gt;&lt;/a&gt; in Rust. A more approachable complement to traditional &lt;a href="https://github.com/tldr-pages/tldr"&gt;&lt;code&gt;man pages&lt;/code&gt;&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/ajeetdsouza/zoxide"&gt;&lt;code&gt;zoxide&lt;/code&gt;&lt;/a&gt;: A smarter cd command. Supports all major shells. Thanks for this one Stefan! &lt;a href="https://twitter.com/buckstefan"&gt;@buckstefan&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some of these tools promise to give &lt;strong&gt;a better performance ⚡&lt;/strong&gt; than the common UNIX commands they are replacing. Others &lt;strong&gt;expand its functionality&lt;/strong&gt; and &lt;strong&gt;improve the colouring 🌈 and presentation of the outputs&lt;/strong&gt;, which is something I'm already enjoying.&lt;/p&gt;

&lt;p&gt;To make them more traction, I added some &lt;code&gt;aliases&lt;/code&gt; in my &lt;code&gt;.bash_profile&lt;/code&gt; to ensure I use them in my daily work. Here's the snippet of bash just in case you want to apply the same aliases I did:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;defineAlias &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
   &lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$2&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null 2&amp;gt;&amp;amp;1 &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;alias&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$2&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

defineAlias &lt;span class="nb"&gt;cat &lt;/span&gt;bat
defineAlias &lt;span class="nb"&gt;ls &lt;/span&gt;exa
defineAlias top btm
defineAlias &lt;span class="nb"&gt;du &lt;/span&gt;dust
defineAlias find fd
defineAlias ps procs
defineAlias &lt;span class="nb"&gt;grep &lt;/span&gt;rg
defineAlias &lt;span class="nb"&gt;sed &lt;/span&gt;sd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;defineAlias()&lt;/code&gt; function does not define the alias if the command does not exist. It is handy if we decide to uninstall one of these tools and forget to remove the alias from our bash profile. I found this code snippet in &lt;a href="https://stackoverflow.com/questions/34391838/best-way-to-define-conditional-aliases-in-shell"&gt;this StackOverflow post&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This post &lt;a href="https://www.oscardom.dev/blog/tooling/command-line-tools"&gt;was initially published on my blog&lt;/a&gt;. Come by and check other publications I have at &lt;a href="https://oscardom.dev"&gt;https://oscardom.dev&lt;/a&gt;  or say hi to me on Twitter: &lt;a href="https://twitter.com/oscard0m_"&gt;@oscard0m_&lt;/a&gt;&lt;/p&gt;

</description>
      <category>rust</category>
      <category>cli</category>
      <category>unix</category>
      <category>bash</category>
    </item>
  </channel>
</rss>
