Routes

Loading "Routing in Remix"
Because routing involves creating files, you're going to need to follow the instructions in this document. There aren't any files for Kody to give you instructions in like usual.
πŸ‘¨β€πŸ’Ό We got our first user! His name is "Kody" 🐨 so we're going to build Kody's user profile page and his notes pages (his username is "kody"). Users in this app have profile pages and can make notes. So, we want to have the following routes:
  1. /users/kody - Kody's profile page
  2. /users/kody/notes - Kody's list of notes
  3. /users/kody/notes/some-note-id - A specific note
These pages will get more interesting in the future, but for now, let's just focus on the routing portion. Your job is to create four route files.
From a layout perspective, we want the profile page to take up the full screen. The notes page should also take up the full screen, but the specific note should be nested inside the notes page.
It could be useful to run the solution app and see what the final result looks like by clicking on the "Solution" tab and running that app.
It's not very important that you memorize the route convention. This is something you will become familiar with over time and you can always refer back to the remix-flat-routes documentation any time you need a refresher.
Let's start with the profile page. Following the route convention, we have a choice of where we can place the file. We can either put it in routes/users.kody.tsx or routes/users+/kody.tsx.
Let's talk about what these special characters mean for remix-flat-routes. The . in users.kody tells remix-flat-routes to separate the users and kody by a /. So users.kody becomes users/kody. The + in users+/kody does the same thing, except it allows you to use a folder instead of an extra-long filename. That's the only difference. In this exercise we're going to go with the +/ here, but we'll use the . in another route.
In this case, because we know we're going to have several routes under the /users path, I think it makes the most sense to use the users+/ directory approach.
🐨 In this file, create a component and export it as the default export. You can start that component out by returning a <div> with a title like this:
export default function KodyProfileRoute() {
	return (
		<div className="container mb-48 mt-36 border-4 border-green-500">
			<h1 className="text-h1">Kody</h1>
		</div>
	)
}
🐨 I'm adding some borders to make it easier for you to notice the relationships between the routes.
🐨 Once you've got that, open .
"Kody" should be displayed on the page. One fun fact, you'll also notice the Epic Notes logo in the header and the footer are on the page as well, even though you didn't render those yourself. That's because you're actually already using nested routing! The route you just created is nested inside !
Now, let's create the notes parent route. All the notes will be "URL Nested" inside /users/kody, but they won't be "Layout Nested," so we'll need to add an underscore (_) to the filename. Also, since we'll have several of these, we'll use the + convention to allow us to put them all in a folder instead of having to have a really long filename.
So let's create the file for the /users/kody/notes route.
Inside of this one, let's start with:
export default function NotesRoute() {
	return (
		<div className="flex h-full justify-between pb-12 border-8 border-blue-500">
			<h1 className="text-h1">Notes</h1>
		</div>
	)
}
🐨 Now you can go to .
The <h1> of "Notes" should be displayed on the page, but the "Kody" from the previous route should not be displayed. That's because we're not using layout nesting here thanks to the _ in the filename.
Great, now let's create the route for a specific note. This one will be nested inside the notes route. For this, I don't think it's very useful to have another folder of nesting, so instead of the +/ syntax for a directory, we'll just add notes. to the filename.
Inside of this one, let's go with:
export default function SomeNoteId() {
	return (
		<div className="container pt-12 border-8 border-red-500">
			<h2 className="text-h2">Some Note</h2>
		</div>
	)
}
Super, now let's go to .
Uh oh! We still just have "Notes" on the screen!? But the URL has our /some-note-id in it.
If you like, you can cd into playground and run npx remix routes. If you do that, it'll print this:
<Routes>
	<Route file="root.tsx">
		<Route index file="routes/index.tsx" />
		<Route path="users/kody" file="routes/users+/kody.tsx" />
		<Route path="users/kody/notes" file="routes/users+/kody_+/notes.tsx">
			<Route
				path="some-note-id"
				file="routes/users+/kody_+/notes.some-note-id.tsx"
			/>
		</Route>
	</Route>
</Routes>
So the routes are definitely right there. What's going on? Well, remember that we're nesting our routes. And we wouldn't want Remix to just stick the UI for each nested route one below the other. As the developer, we want to control where the nesting actually happens. The parent contains the child which contains the grandchild etc. So what we need is to have the parent (/users/kody/notes) to tell Remix where to put the child (/users/kody/notes/some-note-id). And we do this using the <Outlet /> component.
Here's a quick example of how this works:
export default function Parent() {
	return (
		<div>
			<h1>Parent</h1>
			<Outlet />
		</div>
	)
}
export default function Child() {
	return <h2>Child</h2>
}
With that, when you navigate to /parent/child, you'll see "Parent" above "Child". If we swap the <h1> and <Outlet /> in the parent, then the child will be above the parent. The parent gets to decide where its child goes.
🐨 So go ahead and open the file and get the <Outlet /> component from @remix-run/react, then render it below the <h1> we put in there earlier.
Great! Now when we're on , it shows the "Notes" title and the "Some Note" text! πŸŽ‰
Another thing that will be really useful for us is to have some default content that shows up on the /users/kody/notes page when we're not on a specific note. Something like "please select a note" or something. We can do that by adding an index route to the notes route. We'll create that right next to our some-note-id route.
Stick this in there:
export default function NotesIndexRoute() {
	return (
		<div className="container pt-12 border-8 border-purple-500">
			<p className="text-body-md">Select a note</p>
		</div>
	)
}
Now if we navigate to , we'll see the "Select a note" text.
Sweet! You've got nested routing working. πŸŽ‰

Please set the playground first

Loading "Routes"
Loading "Routes"
Login to get access to the exclusive discord channel.
  • general
    Modals / Dialogs
    Lucas Wargha πŸš€ 🌌:
    It seems like modals and dialogs are becoming a hot topic on my team lately. I haven’t found a solid...
    3 Β· 4 days ago
  • πŸ”­foundations
    Prefetching not working?
    Justin Toman πŸ†:
    I'm on 05. Scripting / 04. Prefetching I have the exact solution running (0 diff), I've restarted t...
    • βœ…1
    2 Β· 2 months ago
  • general
    epic stack website initial load at home page is unstyled (sometimes)
    osmancakir πŸš€ 🌌:
    Sometimes (especially when it is loaded first time on a new browser etc.) I see this unstyled versio...
    • βœ…1
    10 Β· 3 months ago
  • general
    Welcome to EpicWeb.dev! Say Hello πŸ‘‹
    Kent C. Dodds β—† πŸš€πŸ†πŸŒŒ:
    This is the first post of many hopefully!
    • 18
    86 Β· 2 years ago
  • general
    Resource / Api endpoints on epic stack / RR7
    Lucas Wargha πŸš€ 🌌:
    Hi everyone! Quick question for those using the Epic Stack: How are you handling resource routes ...
    • βœ…1
    2 Β· 2 months ago
  • general
    Epic stack using tanstack form
    Lucas Wargha πŸš€ 🌌:
    https://github.com/epicweb-dev/epic-stack/compare/epicweb-dev:main...wargha:feature/tanstack-form-ex...
    • βœ…1
    3 Β· 2 months ago
  • general
    Init command outdated on the EpicWeb website
    Virgile πŸ† 🌌:
    Hi everyone. I've initialized a new epic-stack project yesterday. Following instructions from http...
    • βœ…1
    3 Β· 2 months ago
  • general
    Mark as complete, resets the first time you click it.
    Daniel V.C πŸš€ 🌌:
    Not sure if anyone else has had this issue, as i've not seen anyone else talk about it, but I find ...
    • βœ…1
    8 Β· 3 months ago
  • πŸ’Ύdata
    general
    πŸ“forms
    πŸ”­foundations
    double underscore?
    trendaaang 🌌:
    What with the `__note-editor.tsx`? I don't see that in the Remix docs and I don't remember Kent talk...
    • βœ…1
    2 Β· a year ago
  • general
    Keeping Epic Stack Projects Free on Fly – Any Tips?
    Lucas Wargha πŸš€ 🌌:
    I’ve been experimenting with the Epic Stack and deploying some dummy projects on Fly. I noticed that...
    • βœ…1
    0 Β· 3 months ago
  • πŸ’Ύdata
    general
    πŸ“forms
    πŸ”­foundations
    Creating Notes
    Scott 🌌 πŸ†:
    Does anybody know in what workshop we create notes? I would like to see the routing structure. So fa...
    • βœ…1
    2 Β· 5 months ago
  • πŸ”­foundations
    πŸ’Ύdata
    general
    πŸ“forms
    πŸ”auth
    Thank you for the inspiration
    Binalfew πŸš€ 🌌:
    <@105755735731781632> I wanted to thank you for the incredible knowledge I gained from your Epic Web...
    • ❀️1
    1 Β· 5 months ago
  • πŸ”­foundations
    git push returns 400
    mohdelle 🌌:
    when i try to start a fresh epic stack project and push to remote it's going to an error. anyone els...
    • βœ…1
    3 Β· 7 months ago
  • general
    npm install everytime I setup a new playground
    Duki 🌌:
    Is it normal that I have to run `npm install` in my playground directory, everytime I setup the play...
    • βœ…1
    2 Β· 8 months ago
  • πŸ”­foundations
    Progessive Enhancement - React .map
    Scott 🌌 πŸ†:
    I'm reviewing Foundations --> Scripting --> Scripts. I'm wondering how the `.map` works (iterating...
    • βœ…1
    1 Β· 8 months ago
  • πŸ”­foundations
    Parent Data - SEO - Typescript concept help
    remich 🌌:
    I'm relatively new to TS, and I can see the value that Kent is talking about with the second argumen...
    • βœ…1
    1 Β· 10 months ago
  • πŸ’Ύdata
    πŸ“forms
    πŸ”­foundations
    Reviewing foundations, Mutations, Actions
    silvanet πŸš€ 🌌:
    Forgive me for this. I went over the file size limit. I don't want to sign up for being able to exce...
    • βœ…1
    2 Β· a year ago
  • general
    Migration to Vite: Server-only module referenced by client
    Fabian 🌌:
    Hi, I'm working on migrating to Vite following the remix docs (https://remix.run/docs/en/main/guides...
    • βœ…1
    1 Β· 10 months ago
  • πŸ”­foundations
    Styling 05 workshop error: Expected component `CodeFile` to be defined
    jocosage 🌌:
    Is this error intended behaviour, it doesn't look so as in the git repo there seems to be instructio...
    • βœ…1
    3 Β· 9 months ago
  • πŸ”­foundations
    Foundations Review
    Baghira 🌌:
    I finished the foundations workshop. I liked the SEO part and error handling part. Remix built-in to...
    • βœ…2
    1 Β· 9 months ago
  • general
    Remix Vite Plugin
    Binalfew πŸš€ 🌌:
    <@105755735731781632> Now that remix officially supports vite (though not stable) what does it mean...
    • βœ…1
    3 Β· 2 years ago
  • general
    πŸ”­foundations
    Solutions video on localhost:5639 ?
    quang πŸš€ 🌌:
    Hi, so I'm having a hard time navigating (hopefully will be better with time) The nav on epicweb.de...
    • βœ…1
    9 Β· 2 years ago
  • πŸ”­foundations
    Progressive Enhancement & Client Side Scripting
    Chwizdo 🌌:
    I'm currently just starting at foundations | scripting part, and until now, I've heard KCD mentioned...
    • βœ…1
    4 Β· 2 years ago
  • πŸ”­foundations
    Unable to push my changes to Github
    Sachin Purohit 🌌:
    When trying to push changes, I am getting the below error- remote: fatal: did not receive expecte...
    • βœ…1
    3 Β· a year ago
  • general
    Epicshop is now social and mobile friendly!
    Kent C. Dodds β—† πŸš€πŸ†πŸŒŒ:
    I'm excited to announce that now the Epic Web workshops are mobile friendly! https://foundations.ep...
    • πŸŽ‰2
    0 Β· a year ago
  • πŸ”­foundations
    How to fetch data on client (e.g. Combobox)
    QzCurious 🌌 πŸš€:
    After learning from epic web, I'm really into SSR data fetching pattern. I'm now doing SSR all of m...
    • βœ…1
    2 Β· a year ago
  • πŸ”­foundations
    @remix-run/react vs @remix-run/node
    mustak πŸš€ 🌌:
    Module: Search Engine Optimization Exercise: Meta Overrides There are 2 different imports for type ...
    • βœ…1
    2 Β· a year ago
  • πŸ’Ύdata
    πŸ“forms
    πŸ”­foundations
    How can I do this?
    silvanet πŸš€ 🌌:
    Viewing the Intro (from the Workshop) for Mutations, the course has an embedded video where Kent exp...
    • βœ…1
    3 Β· a year ago
  • πŸ”­foundations
    remix flat routes
    mustak πŸš€ 🌌:
    Can someone give me a quick explanation of the following: ```markdown ## underscores with files _fi...
    • βœ…1
    2 Β· a year ago
  • πŸ”­foundations
    How to launch VS Code editor from File links in app using wsl2?
    mustak πŸš€ 🌌:
    I've tried setting environment variables in .env: ```js KCDSHOP_EDITOR=code ``` and ```js KCDSHOP_ED...
    • βœ…1
    5 Β· a year ago
  • πŸ”­foundations
    Meta function not being called
    juliano.brasil 🌌:
    Hi. I'm checking the assets on the foundations module, and something is somehow not working for me (...
    • βœ…1
    7 Β· a year ago