Remix nested URLs without the layout nesting

Yesterday we learned how to create pathless layout routes, which means we can share a layout between routes without sharing the URL routes.

Let’s look at how the opposite would work, nested URLs, but without the nested layout.

Let’s take our new post…


This content originally appeared on DEV Community and was authored by Chris Bongers

Yesterday we learned how to create pathless layout routes, which means we can share a layout between routes without sharing the URL routes.

Let's look at how the opposite would work, nested URLs, but without the nested layout.

Let's take our new post, for example.
The current URL structure is like this: admin/posts/new.

This is great, but the layout is shared like this:

- root
-- admin
--- posts
---- new

What happens if we want this to be a page on its own without inheriting all the layout hierarchy?

- root
-- admin
--- new

Segmented URLs in Remix

This is where segmented URLs come in super handy. We can segment a URL with dots to replicate the URL nesting but not take the styling.

In our case, we can move the new.tsx file to our admin folder and rename it to: posts.new.tsx

If we run our application, our URL will remain the same, but we don't see the posts layout stuff, only the admin layout.

Remix segmented URL

You can even make this multi-level. Let's see what happens if we move the posts.new.tsx file one level up and rename it to admin.posts.new.tsx.

Top level route

Amazing!

As you can see, Remix can support all kinds of use-cases.
You can even use dynamic parameters within these segmented URLs.

We can make all kinds of routes and layout hierarchies between this and the ability to use pathless routes.

You can find this article's code on GitHub.

Thank you for reading, and let's connect!

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter


This content originally appeared on DEV Community and was authored by Chris Bongers


Print Share Comment Cite Upload Translate Updates
APA

Chris Bongers | Sciencx (2022-05-01T05:14:41+00:00) Remix nested URLs without the layout nesting. Retrieved from https://www.scien.cx/2022/05/01/remix-nested-urls-without-the-layout-nesting/

MLA
" » Remix nested URLs without the layout nesting." Chris Bongers | Sciencx - Sunday May 1, 2022, https://www.scien.cx/2022/05/01/remix-nested-urls-without-the-layout-nesting/
HARVARD
Chris Bongers | Sciencx Sunday May 1, 2022 » Remix nested URLs without the layout nesting., viewed ,<https://www.scien.cx/2022/05/01/remix-nested-urls-without-the-layout-nesting/>
VANCOUVER
Chris Bongers | Sciencx - » Remix nested URLs without the layout nesting. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/05/01/remix-nested-urls-without-the-layout-nesting/
CHICAGO
" » Remix nested URLs without the layout nesting." Chris Bongers | Sciencx - Accessed . https://www.scien.cx/2022/05/01/remix-nested-urls-without-the-layout-nesting/
IEEE
" » Remix nested URLs without the layout nesting." Chris Bongers | Sciencx [Online]. Available: https://www.scien.cx/2022/05/01/remix-nested-urls-without-the-layout-nesting/. [Accessed: ]
rf:citation
» Remix nested URLs without the layout nesting | Chris Bongers | Sciencx | https://www.scien.cx/2022/05/01/remix-nested-urls-without-the-layout-nesting/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.