Skip to content

Commit bf7246a

Browse files
committed
Merge branch 'framework'
2 parents e52e353 + edf8cca commit bf7246a

File tree

256 files changed

+4191
-26092
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

256 files changed

+4191
-26092
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ dist
44
dist-ssr
55
*.local
66

7+
.react-router
8+
79
# misc
810
db.json
911
preferences.json

Diff for: app-react-router-framework/.react-router/types/app/+types/root.ts

-40
This file was deleted.

Diff for: app-react-router-framework/.react-router/types/app/routes/+types/home.ts

-40
This file was deleted.

Diff for: app-remix/lessons/01-routes-and-layouts/lecture/root.tsx renamed to app-react-router-framework/LESSONS/01-routes-and-layouts/lecture/root.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Links, Meta, Outlet, Scripts, ScrollRestoration } from '@remix-run/react'
2-
import { LinksFunction } from '@remix-run/node'
3-
import stylesheet from '~/styles/app.css?url'
1+
import { Links, Meta, Outlet, Scripts, ScrollRestoration } from 'react-router'
2+
import { type LinksFunction } from 'react-router'
3+
import stylesheet from '~/index.css?url'
44

55
export const links: LinksFunction = () => [{ rel: 'stylesheet', href: stylesheet }]
66

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { type RouteConfig, index } from '@react-router/dev/routes'
2+
3+
export default [index('./routes/home.tsx')] satisfies RouteConfig
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export default function Page() {
1+
export default function Home() {
22
return <div>Let's get started</div>
33
}

Diff for: app-remix/lessons/01-routes-and-layouts/practice/root.tsx renamed to app-react-router-framework/LESSONS/01-routes-and-layouts/practice-final/root.tsx

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { Links, Meta, Outlet, Scripts, ScrollRestoration } from '@remix-run/react'
2-
import { LinksFunction } from '@remix-run/node'
3-
import stylesheet from '~/styles/app.css?url'
4-
import { MainLayout } from './components/MainLayout'
1+
import { Links, Meta, Outlet, Scripts, ScrollRestoration } from 'react-router'
2+
import { type LinksFunction } from 'react-router'
3+
import stylesheet from '~/index.css?url'
54

65
export const links: LinksFunction = () => [{ rel: 'stylesheet', href: stylesheet }]
76

@@ -20,10 +19,7 @@ export default function App() {
2019
/>
2120
</head>
2221
<body className="p-3">
23-
<MainLayout>
24-
<Outlet />
25-
</MainLayout>
26-
22+
<Outlet />
2723
<ScrollRestoration />
2824
<Scripts />
2925
</body>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { type RouteConfig, index, layout, route } from '@react-router/dev/routes'
2+
3+
export default [
4+
layout('./routes/main-layout.tsx', [
5+
layout('./routes/common-layout.tsx', [
6+
index('./routes/home.tsx'),
7+
route('contact', './routes/contact.tsx'),
8+
]),
9+
route('auth', './routes/auth-layout.tsx', [
10+
route('login', './routes/auth-login.tsx'),
11+
route('register', './routes/auth-register.tsx'),
12+
]),
13+
route('products', './routes/products-layout.tsx', [
14+
index('./routes/products-home.tsx'),
15+
route(':productId', './routes/products-profile.tsx'),
16+
route('special', './routes/products-special.tsx'),
17+
]),
18+
]),
19+
] satisfies RouteConfig

Diff for: app-remix/lessons/01-routes-and-layouts/practice-final/routes/auth.tsx renamed to app-react-router-framework/LESSONS/01-routes-and-layouts/practice-final/routes/auth-layout.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { redirect, type LoaderFunctionArgs } from '@remix-run/node'
2-
import { Outlet } from '@remix-run/react'
1+
import { redirect, type LoaderFunctionArgs } from 'react-router'
2+
import { Outlet } from 'react-router'
33

44
export async function loader({ request }: LoaderFunctionArgs) {
55
if (request.url.replace(/\/$/, '').endsWith('auth')) {

Diff for: app-remix/lessons/01-routes-and-layouts/practice-final/routes/_layout.tsx renamed to app-react-router-framework/LESSONS/01-routes-and-layouts/practice-final/routes/common-layout.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Outlet } from '@remix-run/react'
1+
import { Outlet } from 'react-router'
22

3-
export default function Page() {
3+
export default function CommonLayout() {
44
return (
55
<div className="p-3 bg-slate-300 border rounded space-y-3">
66
<div className="p-3 bg-slate-200 rounded">

Diff for: app-remix/lessons/01-routes-and-layouts/practice-final/components/MainLayout.tsx renamed to app-react-router-framework/LESSONS/01-routes-and-layouts/practice-final/routes/main-layout.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
type Props = {
2-
children: React.ReactNode
3-
}
1+
import { Outlet } from 'react-router'
42

5-
export function MainLayout({ children }: Props) {
3+
export default function MainLayout() {
64
return (
75
<div className="p-3 border-2 border-slate-400 rounded space-y-3 bg-white">
86
<div className="p-3 border-2 border-slate-400 rounded">
97
<h1>Main Layout</h1>
108
</div>
119
<div className="flex gap-3">
1210
<aside className="w-52 min-h-[200px] p-3 border-2 border-slate-400 rounded">Sidebar</aside>
13-
<main className="flex-1">{children}</main>
11+
<main className="flex-1">
12+
<Outlet />
13+
</main>
1414
</div>
1515
</div>
1616
)

Diff for: app-remix/lessons/01-routes-and-layouts/practice-final/routes/products.tsx renamed to app-react-router-framework/LESSONS/01-routes-and-layouts/practice-final/routes/products-layout.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Outlet } from '@remix-run/react'
1+
import { Outlet } from 'react-router'
22

33
export default function Page() {
44
return (

Diff for: app-remix/lessons/01-routes-and-layouts/practice-final/routes/products.$productId.tsx renamed to app-react-router-framework/LESSONS/01-routes-and-layouts/practice-final/routes/products-profile.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useParams } from '@remix-run/react'
1+
import { useParams } from 'react-router'
22

33
export default function Page() {
44
const productId = useParams().productId!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Routes And Layouts
2+
3+
The goal of this practice is to make files for these routes:
4+
5+
```js
6+
// URL SUB LAYOUT CONTENT
7+
// localhost:3000 CommonLayout "Home Page"
8+
// localhost:3000/contact CommonLayout "Contact"
9+
// localhost:3000/auth/login AuthLayout "Login"
10+
// localhost:3000/auth/register AuthLayout "Register"
11+
// localhost:3000/products ProductsLayout "Browse Products"
12+
// localhost:3000/products/1 ProductsLayout "Product Profile: 1"
13+
// localhost:3000/products/special ProductsLayout "Special Product Profile"
14+
```
15+
16+
## Task 1
17+
18+
The only file you'll edit is `routes.tsx`
19+
20+
Each URL the user can visit loads a page, that page will be built from three files: The main layout, a sub-layout, and the page itself. Above you can see which URL someone will visit to see each sub-layout they'll get. All pages and layouts are already made, you just need to assemble the router in `routes.ts`.
21+
22+
Sub layouts are color coded as follows so you can visually see your success:
23+
24+
Gray - Common Layout
25+
Green - AuthLayout
26+
Blue - Product Layout
27+
28+
React Router lets you nest your routing instructions as follows. This example is taken from their docs so lets not assume their file names match up to ours:
29+
30+
```ts
31+
import { type RouteConfig, route, index, layout, prefix } from '@react-router/dev/routes'
32+
33+
export default [
34+
index('./home.tsx'),
35+
route('about', './about.tsx'),
36+
37+
layout('./auth/layout.tsx', [
38+
route('login', './auth/login.tsx'),
39+
route('register', './auth/register.tsx'),
40+
]),
41+
] satisfies RouteConfig
42+
```
43+
44+
Most routes will use the `route()` function in real life. With it, you're simply saying if you visit _this path_ you get _this file_:
45+
46+
```ts
47+
route('this-path', './this-file.tsx')
48+
```
49+
50+
But some sites will use a hierarchy of layouts. To put your page in a layout, wrap its route in the `layout()` function:
51+
52+
```ts
53+
layout('./some-layout.tsx', [
54+
route('page-one', './one.tsx')
55+
route('page-two', './two.tsx')
56+
route('page-three', './three.tsx')
57+
])
58+
```
59+
60+
Layouts don't add anything to the URL. So in this example above, someone would visit `site.com/page-one` and that page would nest inside the `some-layout.tsx` file. But what if you wanted a nested layout AND for a path to be added to the URL like `site.com/path/page-one`? Then use nested `route()` instead
61+
62+
```ts
63+
route('path', './some-layout.tsx', [
64+
route('page-one', './one.tsx') // <--- Now someone can visit /path/page-one in the URL and get this page
65+
route('page-two', './two.tsx')
66+
route('page-three', './three.tsx')
67+
])
68+
```
69+
70+
Now with this example, people can go to `/path/page....` but they can't go to `/path` because we don't have a main index page for it. For that we'll use `index()`:
71+
72+
```ts
73+
route('path', './some-layout.tsx', [
74+
index('/index.tsx') // <--- Now someone can visit /path in the URL and get this page
75+
route('page-one', './one.tsx')
76+
route('page-two', './two.tsx')
77+
route('page-three', './three.tsx')
78+
])
79+
```
80+
81+
## Final
82+
83+
Remember, for this and all practices, there's a `final` version for you to review if you need to with all the answers. In this case, the final is in `practice-final`.

Diff for: app-remix/lessons/01-routes-and-layouts/practice-final/root.tsx renamed to app-react-router-framework/LESSONS/01-routes-and-layouts/practice/root.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Links, Meta, Outlet, Scripts, ScrollRestoration } from '@remix-run/react'
2-
import { LinksFunction } from '@remix-run/node'
3-
import stylesheet from '~/styles/app.css?url'
1+
import { Links, Meta, Outlet, Scripts, ScrollRestoration } from 'react-router'
2+
import { type LinksFunction } from 'react-router'
3+
import stylesheet from '~/index.css?url'
44
import { MainLayout } from './components/MainLayout'
55

66
export const links: LinksFunction = () => [{ rel: 'stylesheet', href: stylesheet }]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { type RouteConfig, index, layout, route } from '@react-router/dev/routes'
2+
3+
export default [
4+
layout('./routes/main-layout.tsx', [
5+
// Other routes here:
6+
// index()
7+
// layout()
8+
// route()
9+
]),
10+
] satisfies RouteConfig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { redirect, type LoaderFunctionArgs } from 'react-router'
2+
import { Outlet } from 'react-router'
3+
4+
export async function loader({ request }: LoaderFunctionArgs) {
5+
if (request.url.replace(/\/$/, '').endsWith('auth')) {
6+
return redirect('/auth/login')
7+
}
8+
9+
return null
10+
}
11+
12+
export default function Page() {
13+
return (
14+
<div className="p-3 bg-green-300 border rounded space-y-3">
15+
<div className="p-3 bg-green-200 rounded">
16+
<h1>Auth Layout</h1>
17+
</div>
18+
<main className="p-3 bg-green-200 rounded">
19+
<Outlet />
20+
</main>
21+
</div>
22+
)
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function Page() {
2+
return (
3+
<div>
4+
<h1>Login</h1>
5+
</div>
6+
)
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function Page() {
2+
return (
3+
<div>
4+
<h1>Register</h1>
5+
</div>
6+
)
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Outlet } from 'react-router'
2+
3+
export default function CommonLayout() {
4+
return (
5+
<div className="p-3 bg-slate-300 border rounded space-y-3">
6+
<div className="p-3 bg-slate-200 rounded">
7+
<h1>Common Layout</h1>
8+
</div>
9+
<div className="flex gap-3">
10+
<main className="flex-1 p-3 bg-slate-200 rounded">
11+
<Outlet />
12+
</main>
13+
<aside className="w-52 min-h-[200px] p-3 bg-slate-200 rounded">Sidebar</aside>
14+
</div>
15+
</div>
16+
)
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function Page() {
2+
return (
3+
<div>
4+
<h1>Contact</h1>
5+
</div>
6+
)
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function Page() {
2+
return (
3+
<div>
4+
<h1>Home Page</h1>
5+
</div>
6+
)
7+
}

0 commit comments

Comments
 (0)