Next 13 - Trying out routes

I'm a full-stack developer from South Africa πΏπ¦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa πΏπ¦. I love writing about JavaScript, HTML and CSS.
Hello, How are you?
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

If you are an avid reader of my blogs, you'll learn that I learn best by trying things out.
This article will look at the new Next 13 ways of routing.
To get started, we first have to install a new Next 13 app, which is created with the following command at the time of writing.
npx create-next-app@latest --experimental-app
If we open up the project, we already see that inside our app directory, we get a layout.tsx, and page.tsx file.
The layout file is responsible for our layout and the page for our / home page.
We can go multiple routes to add a new page, but let's say we want to create the following pages.
To achieve this, we have to start by creating our dashboard folder. This folder can eventually hold our global dashboard layout.
Create the settings and account folders in that folder.
And again, inside those, go ahead and create a page.tsx for each.
The whole structure will look like this:
I do like how this makes every component very clear and explanatory of what it does.
Each page will return what it's on for now.
As for the settings/page.tsx, we use the following.
export default function SettingsPage() {
return <h1>This is my settings page</h1>;
}
And for the account page:
export default function AccountPage() {
return <h1>This is my account page</h1>;
}
Now, if you run your application with npm run dev, we will be able to visit both on:
http://localhost:3000/dashboard/settingshttp://localhost:3000/dashboard/accountPerhaps you like having combined layouts for the settings and account, but you don't want to include the dashboard param in the URL.
For this, we can leverage routing groups, which refer to a group of routes that can share a layout but doesn't get added to the URL.
To achieve this, rename dashboard to (dashboard).
And now, we can visit our pages on the following URLs.
http://localhost:3000/settingshttp://localhost:3000/accountWe can achieve a lot of excellent routing options with the new flows. They make it super dynamic yet flexible to layout out from here.
In the following article, we'll look at how the layout will look and what will be shared between the pages.
If you are keen, I uploaded the code to GitHub, so you can look over it.
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter