mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-06 04:22:01 +00:00
[examples] Update Remix template for latest. (#8857)
From `create-remix`
This commit is contained in:
@@ -8,6 +8,13 @@ This directory is a brief example of a [Remix](https://remix.run/docs) site that
|
||||
|
||||
_Live Example: https://remix-run-template.vercel.app_
|
||||
|
||||
You can also deploy using the [Vercel CLI](https://vercel.com/cli):
|
||||
|
||||
```sh
|
||||
npm i -g vercel
|
||||
vercel
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
To run your Remix app locally, make sure your project's local dependencies are installed:
|
||||
@@ -23,5 +30,3 @@ npm run dev
|
||||
```
|
||||
|
||||
Open up [http://localhost:3000](http://localhost:3000) and you should be ready to go!
|
||||
|
||||
If you're used to using the `vercel dev` command provided by [Vercel CLI](https://vercel.com/cli) instead, you can also use that, but it's not needed.
|
||||
|
||||
@@ -1,4 +1,22 @@
|
||||
import { RemixBrowser } from "@remix-run/react";
|
||||
import { hydrate } from "react-dom";
|
||||
import { startTransition, StrictMode } from "react";
|
||||
import { hydrateRoot } from "react-dom/client";
|
||||
|
||||
hydrate(<RemixBrowser />, document);
|
||||
function hydrate() {
|
||||
startTransition(() => {
|
||||
hydrateRoot(
|
||||
document,
|
||||
<StrictMode>
|
||||
<RemixBrowser />
|
||||
</StrictMode>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
if (window.requestIdleCallback) {
|
||||
window.requestIdleCallback(hydrate);
|
||||
} else {
|
||||
// Safari doesn't support requestIdleCallback
|
||||
// https://caniuse.com/requestidlecallback
|
||||
window.setTimeout(hydrate, 1);
|
||||
}
|
||||
|
||||
@@ -8,14 +8,14 @@ export default function handleRequest(
|
||||
responseHeaders: Headers,
|
||||
remixContext: EntryContext
|
||||
) {
|
||||
let markup = renderToString(
|
||||
const markup = renderToString(
|
||||
<RemixServer context={remixContext} url={request.url} />
|
||||
);
|
||||
|
||||
responseHeaders.set("Content-Type", "text/html");
|
||||
|
||||
return new Response("<!DOCTYPE html>" + markup, {
|
||||
status: responseStatusCode,
|
||||
headers: responseHeaders,
|
||||
status: responseStatusCode,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,182 +1,34 @@
|
||||
import type { LinksFunction, MetaFunction } from "@remix-run/node";
|
||||
import type { MetaFunction } from "@remix-run/node";
|
||||
import {
|
||||
Link,
|
||||
Links,
|
||||
LiveReload,
|
||||
Meta,
|
||||
Outlet,
|
||||
Scripts,
|
||||
ScrollRestoration,
|
||||
useCatch,
|
||||
} from "@remix-run/react";
|
||||
import { Analytics } from '@vercel/analytics/react';
|
||||
|
||||
import darkStylesUrl from "~/styles/dark.css";
|
||||
import globalStylesUrl from "~/styles/global.css";
|
||||
|
||||
// https://remix.run/api/conventions#links
|
||||
export let links: LinksFunction = () => {
|
||||
return [
|
||||
{ rel: "stylesheet", href: globalStylesUrl },
|
||||
{
|
||||
rel: "stylesheet",
|
||||
href: darkStylesUrl,
|
||||
media: "(prefers-color-scheme: dark)"
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
// https://remix.run/api/conventions#meta
|
||||
export let meta: MetaFunction = () => ({
|
||||
export const meta: MetaFunction = () => ({
|
||||
charset: "utf-8",
|
||||
title: "New Remix App",
|
||||
viewport: "width=device-width,initial-scale=1",
|
||||
});
|
||||
|
||||
// https://remix.run/api/conventions#default-export
|
||||
// https://remix.run/api/conventions#route-filenames
|
||||
export default function App() {
|
||||
return (
|
||||
<Document>
|
||||
<Layout>
|
||||
<Outlet />
|
||||
</Layout>
|
||||
</Document>
|
||||
);
|
||||
}
|
||||
|
||||
// https://remix.run/api/conventions#errorboundary
|
||||
export function ErrorBoundary({ error }: { error: Error }) {
|
||||
console.error(error);
|
||||
return (
|
||||
<Document title="Error!">
|
||||
<Layout>
|
||||
<div>
|
||||
<h1>There was an error</h1>
|
||||
<p>{error.message}</p>
|
||||
<hr />
|
||||
<p>
|
||||
Hey, developer, you should replace this with what you want your
|
||||
users to see.
|
||||
</p>
|
||||
</div>
|
||||
</Layout>
|
||||
</Document>
|
||||
);
|
||||
}
|
||||
|
||||
// https://remix.run/api/conventions#catchboundary
|
||||
export function CatchBoundary() {
|
||||
let caught = useCatch();
|
||||
|
||||
let message;
|
||||
switch (caught.status) {
|
||||
case 401:
|
||||
message = (
|
||||
<p>
|
||||
Oops! Looks like you tried to visit a page that you do not have access
|
||||
to.
|
||||
</p>
|
||||
);
|
||||
break;
|
||||
case 404:
|
||||
message = (
|
||||
<p>Oops! Looks like you tried to visit a page that does not exist.</p>
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Error(caught.data || caught.statusText);
|
||||
}
|
||||
|
||||
return (
|
||||
<Document title={`${caught.status} ${caught.statusText}`}>
|
||||
<Layout>
|
||||
<h1>
|
||||
{caught.status}: {caught.statusText}
|
||||
</h1>
|
||||
{message}
|
||||
</Layout>
|
||||
</Document>
|
||||
);
|
||||
}
|
||||
|
||||
function Document({
|
||||
children,
|
||||
title
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
title?: string;
|
||||
}) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<head>
|
||||
{title ? <title>{title}</title> : null}
|
||||
<Meta />
|
||||
<Links />
|
||||
</head>
|
||||
<body>
|
||||
{children}
|
||||
<Outlet />
|
||||
<ScrollRestoration />
|
||||
<Scripts />
|
||||
<LiveReload />
|
||||
<Analytics />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
||||
function Layout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<div className="remix-app">
|
||||
<header className="remix-app__header">
|
||||
<div className="container remix-app__header-content">
|
||||
<Link to="/" title="Remix" className="remix-app__header-home-link">
|
||||
<RemixLogo />
|
||||
</Link>
|
||||
<nav aria-label="Main navigation" className="remix-app__header-nav">
|
||||
<ul>
|
||||
<li>
|
||||
<Link to="/">Home</Link>
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://remix.run/docs">Remix Docs</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="https://github.com/remix-run/remix">GitHub</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
<div className="remix-app__main">
|
||||
<div className="container remix-app__main-content">{children}</div>
|
||||
</div>
|
||||
<footer className="remix-app__footer">
|
||||
<div className="container remix-app__footer-content">
|
||||
<p>© You!</p>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function RemixLogo() {
|
||||
return (
|
||||
<svg
|
||||
viewBox="0 0 659 165"
|
||||
version="1.1"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlnsXlink="http://www.w3.org/1999/xlink"
|
||||
aria-labelledby="remix-run-logo-title"
|
||||
role="img"
|
||||
width="106"
|
||||
height="30"
|
||||
fill="currentColor"
|
||||
>
|
||||
<title id="remix-run-logo-title">Remix Logo</title>
|
||||
<path d="M0 161V136H45.5416C53.1486 136 54.8003 141.638 54.8003 145V161H0Z M133.85 124.16C135.3 142.762 135.3 151.482 135.3 161H92.2283C92.2283 158.927 92.2653 157.03 92.3028 155.107C92.4195 149.128 92.5411 142.894 91.5717 130.304C90.2905 111.872 82.3473 107.776 67.7419 107.776H54.8021H0V74.24H69.7918C88.2407 74.24 97.4651 68.632 97.4651 53.784C97.4651 40.728 88.2407 32.816 69.7918 32.816H0V0H77.4788C119.245 0 140 19.712 140 51.2C140 74.752 125.395 90.112 105.665 92.672C122.32 96 132.057 105.472 133.85 124.16Z" />
|
||||
<path d="M229.43 120.576C225.59 129.536 218.422 133.376 207.158 133.376C194.614 133.376 184.374 126.72 183.35 112.64H263.478V101.12C263.478 70.1437 243.254 44.0317 205.11 44.0317C169.526 44.0317 142.902 69.8877 142.902 105.984C142.902 142.336 169.014 164.352 205.622 164.352C235.83 164.352 256.822 149.76 262.71 123.648L229.43 120.576ZM183.862 92.6717C185.398 81.9197 191.286 73.7277 204.598 73.7277C216.886 73.7277 223.542 82.4317 224.054 92.6717H183.862Z" />
|
||||
<path d="M385.256 66.5597C380.392 53.2477 369.896 44.0317 349.672 44.0317C332.52 44.0317 320.232 51.7117 314.088 64.2557V47.1037H272.616V161.28H314.088V105.216C314.088 88.0638 318.952 76.7997 332.52 76.7997C345.064 76.7997 348.136 84.9917 348.136 100.608V161.28H389.608V105.216C389.608 88.0638 394.216 76.7997 408.04 76.7997C420.584 76.7997 423.4 84.9917 423.4 100.608V161.28H464.872V89.5997C464.872 65.7917 455.656 44.0317 424.168 44.0317C404.968 44.0317 391.4 53.7597 385.256 66.5597Z" />
|
||||
<path d="M478.436 47.104V161.28H519.908V47.104H478.436ZM478.18 36.352H520.164V0H478.18V36.352Z" />
|
||||
<path d="M654.54 47.1035H611.788L592.332 74.2395L573.388 47.1035H527.564L568.78 103.168L523.98 161.28H566.732L589.516 130.304L612.3 161.28H658.124L613.068 101.376L654.54 47.1035Z" />
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
import type { MetaFunction, LinksFunction } from "@remix-run/node";
|
||||
import { Outlet } from "@remix-run/react";
|
||||
|
||||
import stylesUrl from "~/styles/demos/about.css";
|
||||
|
||||
export let meta: MetaFunction = () => {
|
||||
return {
|
||||
title: "About Remix"
|
||||
};
|
||||
};
|
||||
|
||||
export let links: LinksFunction = () => {
|
||||
return [{ rel: "stylesheet", href: stylesUrl }];
|
||||
};
|
||||
|
||||
export default function Index() {
|
||||
return (
|
||||
<div className="about">
|
||||
<div className="about__intro">
|
||||
<h2>About Us</h2>
|
||||
<p>
|
||||
Ok, so this page isn't really <em>about us</em>, but we did want to
|
||||
show you a few more things Remix can do.
|
||||
</p>
|
||||
<p>
|
||||
Did you notice that things look a little different on this page? The
|
||||
CSS that we import in the route file and include in its{" "}
|
||||
<code>links</code> export is only included on this route and its
|
||||
children.
|
||||
</p>
|
||||
<p>
|
||||
Wait a sec...<em>its children</em>? To understand what we mean by
|
||||
this,{" "}
|
||||
<a href="https://remix.run/docs/en/v1/guides/routing">
|
||||
read all about nested routes in the docs
|
||||
</a>
|
||||
.
|
||||
</p>
|
||||
<hr />
|
||||
<Outlet />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
import { Link } from "@remix-run/react";
|
||||
|
||||
export default function AboutIndex() {
|
||||
return (
|
||||
<div>
|
||||
<p>
|
||||
You are looking at the index route for the <code>/about</code> URL
|
||||
segment, but there are nested routes as well!
|
||||
</p>
|
||||
<p>
|
||||
<strong>
|
||||
<Link to="whoa">Check out one of them here.</Link>
|
||||
</strong>
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import { Link } from "@remix-run/react";
|
||||
|
||||
export default function AboutIndex() {
|
||||
return (
|
||||
<div>
|
||||
<p>
|
||||
Whoa, this is a nested route! We render the <code>/about</code> layout
|
||||
route component, and its <code>Outlet</code> renders our route
|
||||
component. 🤯
|
||||
</p>
|
||||
<p>
|
||||
<strong>
|
||||
<Link to="..">
|
||||
Go back to the <code>/about</code> index.
|
||||
</Link>
|
||||
</strong>
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
import type { ActionFunction } from "@remix-run/node";
|
||||
import { json, redirect } from "@remix-run/node";
|
||||
import { Form, useActionData } from "@remix-run/react";
|
||||
import { useEffect, useRef } from "react";
|
||||
|
||||
export function meta() {
|
||||
return { title: "Actions Demo" };
|
||||
}
|
||||
|
||||
// When your form sends a POST, the action is called on the server.
|
||||
// - https://remix.run/api/conventions#action
|
||||
// - https://remix.run/guides/data-updates
|
||||
export let action: ActionFunction = async ({ request }) => {
|
||||
let formData = await request.formData();
|
||||
let answer = formData.get("answer");
|
||||
|
||||
// Typical action workflows start with validating the form data that just came
|
||||
// over the network. Clientside validation is fine, but you definitely need it
|
||||
// server side. If there's a problem, return the the data and the component
|
||||
// can render it.
|
||||
if (typeof answer !== "string") {
|
||||
return json("Come on, at least try!", { status: 400 });
|
||||
}
|
||||
|
||||
if (answer !== "egg") {
|
||||
return json(`Sorry, ${answer} is not right.`, { status: 400 });
|
||||
}
|
||||
|
||||
// Finally, if the data is valid, you'll typically write to a database or send or
|
||||
// email or log the user in, etc. It's recommended to redirect after a
|
||||
// successful action, even if it's to the same place so that non-JavaScript workflows
|
||||
// from the browser doesn't repost the data if the user clicks back.
|
||||
return redirect("/demos/correct");
|
||||
};
|
||||
|
||||
export default function ActionsDemo() {
|
||||
// https://remix.run/api/remix#useactiondata
|
||||
let actionMessage = useActionData<string>();
|
||||
let answerRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
// This form works without JavaScript, but when we have JavaScript we can make
|
||||
// the experience better by selecting the input on wrong answers! Go ahead, disable
|
||||
// JavaScript in your browser and see what happens.
|
||||
useEffect(() => {
|
||||
if (actionMessage && answerRef.current) {
|
||||
answerRef.current.select();
|
||||
}
|
||||
}, [actionMessage]);
|
||||
|
||||
return (
|
||||
<div className="remix__page">
|
||||
<main>
|
||||
<h2>Actions!</h2>
|
||||
<p>
|
||||
This form submission will send a post request that we handle in our
|
||||
`action` export. Any route can export an action to handle data
|
||||
mutations.
|
||||
</p>
|
||||
<Form method="post" className="remix__form">
|
||||
<h3>Post an Action</h3>
|
||||
<p>
|
||||
<i>What is more useful when it is broken?</i>
|
||||
</p>
|
||||
<label>
|
||||
<div>Answer:</div>
|
||||
<input ref={answerRef} name="answer" type="text" />
|
||||
</label>
|
||||
<div>
|
||||
<button>Answer!</button>
|
||||
</div>
|
||||
{actionMessage ? (
|
||||
<p>
|
||||
<b>{actionMessage}</b>
|
||||
</p>
|
||||
) : null}
|
||||
</Form>
|
||||
</main>
|
||||
|
||||
<aside>
|
||||
<h3>Additional Resources</h3>
|
||||
<ul>
|
||||
<li>
|
||||
Guide:{" "}
|
||||
<a href="https://remix.run/guides/data-writes">Data Writes</a>
|
||||
</li>
|
||||
<li>
|
||||
API:{" "}
|
||||
<a href="https://remix.run/api/conventions#action">
|
||||
Route Action Export
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
API:{" "}
|
||||
<a href="https://remix.run/api/remix#useactiondata">
|
||||
<code>useActionData</code>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</aside>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export default function NiceWork() {
|
||||
return <h1>You got it right!</h1>;
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
import type { MetaFunction } from "@remix-run/node";
|
||||
import { json } from "@remix-run/node";
|
||||
import { Link, Outlet, useCatch, useLoaderData } from "@remix-run/react";
|
||||
|
||||
export let meta: MetaFunction = () => ({ title: "Boundaries Demo" });
|
||||
|
||||
export default function Boundaries() {
|
||||
return (
|
||||
<div className="remix__page">
|
||||
<main>
|
||||
<Outlet />
|
||||
</main>
|
||||
|
||||
<aside>
|
||||
<h2>Click these Links</h2>
|
||||
<ul>
|
||||
<li>
|
||||
<Link to=".">Start over</Link>
|
||||
</li>
|
||||
<li>
|
||||
<Link to="one">
|
||||
Param: <i>one</i>
|
||||
</Link>
|
||||
</li>
|
||||
<li>
|
||||
<Link to="two">
|
||||
Param: <i>two</i>
|
||||
</Link>
|
||||
</li>
|
||||
<li>
|
||||
<Link to="this-record-does-not-exist">This will be a 404</Link>
|
||||
</li>
|
||||
<li>
|
||||
<Link to="shh-its-a-secret">And this will be 401 Unauthorized</Link>
|
||||
</li>
|
||||
<li>
|
||||
<Link to="kaboom">This one will throw an error</Link>
|
||||
</li>
|
||||
</ul>
|
||||
</aside>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
import type { LoaderFunction, MetaFunction } from "@remix-run/node";
|
||||
import { json } from "@remix-run/node";
|
||||
import { Link, useCatch, useLoaderData } from "@remix-run/react";
|
||||
|
||||
// The `$` in route filenames becomes a pattern that's parsed from the URL and
|
||||
// passed to your loaders so you can look up data.
|
||||
// - https://remix.run/api/conventions#loader-params
|
||||
export let loader: LoaderFunction = async ({ params }) => {
|
||||
// pretend like we're using params.id to look something up in the db
|
||||
|
||||
if (params.id === "this-record-does-not-exist") {
|
||||
// If the record doesn't exist we can't render the route normally, so
|
||||
// instead we throw a 404 reponse to stop running code here and show the
|
||||
// user the catch boundary.
|
||||
throw new Response("Not Found", { status: 404 });
|
||||
}
|
||||
|
||||
// now pretend like the record exists but the user just isn't authorized to
|
||||
// see it.
|
||||
if (params.id === "shh-its-a-secret") {
|
||||
// Again, we can't render the component if the user isn't authorized. You
|
||||
// can even put data in the response that might help the user rectify the
|
||||
// issue! Like emailing the webmaster for access to the page. (Oh, right,
|
||||
// `json` is just a Response helper that makes it easier to send JSON
|
||||
// responses).
|
||||
throw json({ webmasterEmail: "hello@remix.run" }, { status: 401 });
|
||||
}
|
||||
|
||||
// Sometimes your code just blows up and you never anticipated it. Remix will
|
||||
// automatically catch it and send the UI to the error boundary.
|
||||
if (params.id === "kaboom") {
|
||||
lol();
|
||||
}
|
||||
|
||||
// but otherwise the record was found, user has access, so we can do whatever
|
||||
// else we needed to in the loader and return the data. (This is boring, we're
|
||||
// just gonna return the params.id).
|
||||
return { param: params.id };
|
||||
};
|
||||
|
||||
export default function ParamDemo() {
|
||||
let data = useLoaderData();
|
||||
return (
|
||||
<h1>
|
||||
The param is <i style={{ color: "red" }}>{data.param}</i>
|
||||
</h1>
|
||||
);
|
||||
}
|
||||
|
||||
// https://remix.run/api/conventions#catchboundary
|
||||
// https://remix.run/api/remix#usecatch
|
||||
// https://remix.run/api/guides/not-found
|
||||
export function CatchBoundary() {
|
||||
let caught = useCatch();
|
||||
|
||||
let message: React.ReactNode;
|
||||
switch (caught.status) {
|
||||
case 401:
|
||||
message = (
|
||||
<p>
|
||||
Looks like you tried to visit a page that you do not have access to.
|
||||
Maybe ask the webmaster ({caught.data.webmasterEmail}) for access.
|
||||
</p>
|
||||
);
|
||||
case 404:
|
||||
message = (
|
||||
<p>Looks like you tried to visit a page that does not exist.</p>
|
||||
);
|
||||
default:
|
||||
message = (
|
||||
<p>
|
||||
There was a problem with your request!
|
||||
<br />
|
||||
{caught.status} {caught.statusText}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<h2>Oops!</h2>
|
||||
<p>{message}</p>
|
||||
<p>
|
||||
(Isn't it cool that the user gets to stay in context and try a different
|
||||
link in the parts of the UI that didn't blow up?)
|
||||
</p>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
// https://remix.run/api/conventions#errorboundary
|
||||
// https://remix.run/api/guides/not-found
|
||||
export function ErrorBoundary({ error }: { error: Error }) {
|
||||
console.error(error);
|
||||
return (
|
||||
<>
|
||||
<h2>Error!</h2>
|
||||
<p>{error.message}</p>
|
||||
<p>
|
||||
(Isn't it cool that the user gets to stay in context and try a different
|
||||
link in the parts of the UI that didn't blow up?)
|
||||
</p>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export let meta: MetaFunction = ({ data }) => {
|
||||
return {
|
||||
title: data ? `Param: ${data.param}` : "Oops...",
|
||||
};
|
||||
};
|
||||
@@ -1,41 +0,0 @@
|
||||
import type { LoaderFunction } from "@remix-run/node";
|
||||
import { json } from "@remix-run/node";
|
||||
import { Link, Outlet, useCatch, useLoaderData } from "@remix-run/react";
|
||||
|
||||
export default function Boundaries() {
|
||||
return (
|
||||
<>
|
||||
<h2>Params</h2>
|
||||
<p>
|
||||
When you name a route segment with $ like{" "}
|
||||
<code>routes/users/$userId.js</code>, the $ segment will be parsed from
|
||||
the URL and sent to your loaders and actions by the same name.
|
||||
</p>
|
||||
<h2>Errors</h2>
|
||||
<p>
|
||||
When a route throws and error in it's action, loader, or component,
|
||||
Remix automatically catches it, won't even try to render the component,
|
||||
but it will render the route's ErrorBoundary instead. If the route
|
||||
doesn't have one, it will bubble up to the routes above it until it hits
|
||||
the root.
|
||||
</p>
|
||||
<p>So be as granular as you want with your error handling.</p>
|
||||
<h2>Not Found</h2>
|
||||
<p>
|
||||
(and other{" "}
|
||||
<a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses">
|
||||
client errors
|
||||
</a>
|
||||
)
|
||||
</p>
|
||||
<p>
|
||||
Loaders and Actions can throw a <code>Response</code> instead of an
|
||||
error and Remix will render the CatchBoundary instead of the component.
|
||||
This is great when loading data from a database isn't found. As soon as
|
||||
you know you can't render the component normally, throw a 404 response
|
||||
and send your app into the catch boundary. Just like error boundaries,
|
||||
catch boundaries bubble, too.
|
||||
</p>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,101 +1,32 @@
|
||||
import type { MetaFunction, LoaderFunction } from "@remix-run/node";
|
||||
import { json } from "@remix-run/node";
|
||||
import { Link, useLoaderData } from "@remix-run/react";
|
||||
|
||||
type IndexData = {
|
||||
resources: Array<{ name: string; url: string }>;
|
||||
demos: Array<{ name: string; to: string }>;
|
||||
};
|
||||
|
||||
// Loaders provide data to components and are only ever called on the server, so
|
||||
// you can connect to a database or run any server side code you want right next
|
||||
// to the component that renders it.
|
||||
// https://remix.run/api/conventions#loader
|
||||
export let loader: LoaderFunction = () => {
|
||||
let data: IndexData = {
|
||||
resources: [
|
||||
{
|
||||
name: "Remix Docs",
|
||||
url: "https://remix.run/docs"
|
||||
},
|
||||
{
|
||||
name: "React Router Docs",
|
||||
url: "https://reactrouter.com/docs"
|
||||
},
|
||||
{
|
||||
name: "Remix Discord",
|
||||
url: "https://discord.gg/VBePs6d"
|
||||
}
|
||||
],
|
||||
demos: [
|
||||
{
|
||||
to: "demos/actions",
|
||||
name: "Actions"
|
||||
},
|
||||
{
|
||||
to: "demos/about",
|
||||
name: "Nested Routes, CSS loading/unloading"
|
||||
},
|
||||
{
|
||||
to: "demos/params",
|
||||
name: "URL Params and Error Boundaries"
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
// https://remix.run/api/remix#json
|
||||
return json(data);
|
||||
};
|
||||
|
||||
// https://remix.run/api/conventions#meta
|
||||
export let meta: MetaFunction = () => {
|
||||
return {
|
||||
title: "Remix Starter",
|
||||
description: "Welcome to remix!"
|
||||
};
|
||||
};
|
||||
|
||||
// https://remix.run/guides/routing#index-routes
|
||||
export default function Index() {
|
||||
let data = useLoaderData<IndexData>();
|
||||
|
||||
return (
|
||||
<div className="remix__page">
|
||||
<main>
|
||||
<h2>Welcome to Remix!</h2>
|
||||
<p>We're stoked that you're here. 🥳</p>
|
||||
<p>
|
||||
Feel free to take a look around the code to see how Remix does things,
|
||||
it might be a bit different than what you’re used to. When you're
|
||||
ready to dive deeper, we've got plenty of resources to get you
|
||||
up-and-running quickly.
|
||||
</p>
|
||||
<p>
|
||||
Check out all the demos in this starter, and then just delete the{" "}
|
||||
<code>app/routes/demos</code> and <code>app/styles/demos</code>{" "}
|
||||
folders when you're ready to turn this into your next project.
|
||||
</p>
|
||||
</main>
|
||||
<aside>
|
||||
<h2>Demos In This App</h2>
|
||||
<ul>
|
||||
{data.demos.map(demo => (
|
||||
<li key={demo.to} className="remix__page__resource">
|
||||
<Link to={demo.to} prefetch="intent">
|
||||
{demo.name}
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<h2>Resources</h2>
|
||||
<ul>
|
||||
{data.resources.map(resource => (
|
||||
<li key={resource.url} className="remix__page__resource">
|
||||
<a href={resource.url}>{resource.name}</a>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</aside>
|
||||
<div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.4" }}>
|
||||
<h1>Welcome to Remix</h1>
|
||||
<ul>
|
||||
<li>
|
||||
<a
|
||||
target="_blank"
|
||||
href="https://remix.run/tutorials/blog"
|
||||
rel="noreferrer"
|
||||
>
|
||||
15m Quickstart Blog Tutorial
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a
|
||||
target="_blank"
|
||||
href="https://remix.run/tutorials/jokes"
|
||||
rel="noreferrer"
|
||||
>
|
||||
Deep Dive Jokes App Tutorial
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a target="_blank" href="https://remix.run/docs" rel="noreferrer">
|
||||
Remix Docs
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
:root {
|
||||
--color-foreground: hsl(0, 0%, 100%);
|
||||
--color-background: hsl(0, 0%, 7%);
|
||||
--color-links: hsl(213, 100%, 73%);
|
||||
--color-links-hover: hsl(213, 100%, 80%);
|
||||
--color-border: hsl(0, 0%, 25%);
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Whoa whoa whoa, wait a sec...why are we overriding global CSS selectors?
|
||||
* Isn't that kind of scary? How do we know this won't have side effects?
|
||||
*
|
||||
* In Remix, CSS that is included in a route file will *only* show up on that
|
||||
* route (and for nested routes, its children). When the user navigates away
|
||||
* from that route the CSS files linked from those routes will be automatically
|
||||
* unloaded, making your styles much easier to predict and control.
|
||||
*
|
||||
* Read more about styling routes in the docs:
|
||||
* https://remix.run/guides/styling
|
||||
*/
|
||||
|
||||
:root {
|
||||
--color-foreground: hsl(0, 0%, 7%);
|
||||
--color-background: hsl(56, 100%, 50%);
|
||||
--color-links: hsl(345, 56%, 39%);
|
||||
--color-links-hover: hsl(345, 51%, 49%);
|
||||
--color-border: rgb(184, 173, 20);
|
||||
--font-body: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
|
||||
Liberation Mono, Courier New, monospace;
|
||||
}
|
||||
|
||||
.about__intro {
|
||||
max-width: 500px;
|
||||
}
|
||||
@@ -1,216 +0,0 @@
|
||||
/*
|
||||
* You can just delete everything here or keep whatever you like, it's just a
|
||||
* quick baseline!
|
||||
*/
|
||||
:root {
|
||||
--color-foreground: hsl(0, 0%, 7%);
|
||||
--color-background: hsl(0, 0%, 100%);
|
||||
--color-links: hsl(213, 100%, 52%);
|
||||
--color-links-hover: hsl(213, 100%, 43%);
|
||||
--color-border: hsl(0, 0%, 82%);
|
||||
--font-body: -apple-system, "Segoe UI", Helvetica Neue, Helvetica, Roboto,
|
||||
Arial, sans-serif, system-ui, "Apple Color Emoji", "Segoe UI Emoji";
|
||||
}
|
||||
|
||||
html {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
box-sizing: inherit;
|
||||
}
|
||||
|
||||
:-moz-focusring {
|
||||
outline: auto;
|
||||
}
|
||||
|
||||
:focus {
|
||||
outline: var(--color-links) solid 2px;
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
background-color: var(--color-background);
|
||||
color: var(--color-foreground);
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: var(--font-body);
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--color-links);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: var(--color-links-hover);
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
hr {
|
||||
display: block;
|
||||
height: 1px;
|
||||
border: 0;
|
||||
background-color: var(--color-border);
|
||||
margin-top: 2rem;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
input:where([type="text"]),
|
||||
input:where([type="search"]) {
|
||||
display: block;
|
||||
border: 1px solid var(--color-border);
|
||||
width: 100%;
|
||||
font: inherit;
|
||||
line-height: 1;
|
||||
height: calc(1ch + 1.5em);
|
||||
padding-right: 0.5em;
|
||||
padding-left: 0.5em;
|
||||
background-color: hsl(0 0% 100% / 20%);
|
||||
color: var(--color-foreground);
|
||||
}
|
||||
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
padding: 0;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap;
|
||||
border-width: 0;
|
||||
}
|
||||
|
||||
.container {
|
||||
--gutter: 16px;
|
||||
width: 1024px;
|
||||
max-width: calc(100% - var(--gutter) * 2);
|
||||
margin-right: auto;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.remix-app {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 100vh;
|
||||
min-height: calc(100vh - env(safe-area-inset-bottom));
|
||||
}
|
||||
|
||||
.remix-app > * {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.remix-app__header {
|
||||
padding-top: 1rem;
|
||||
padding-bottom: 1rem;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.remix-app__header-content {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.remix-app__header-home-link {
|
||||
width: 106px;
|
||||
height: 30px;
|
||||
color: var(--color-foreground);
|
||||
}
|
||||
|
||||
.remix-app__header-nav ul {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1.5em;
|
||||
}
|
||||
|
||||
.remix-app__header-nav li {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.remix-app__main {
|
||||
flex: 1 1 100%;
|
||||
}
|
||||
|
||||
.remix-app__footer {
|
||||
padding-top: 1rem;
|
||||
padding-bottom: 1rem;
|
||||
border-top: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.remix-app__footer-content {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.remix__page {
|
||||
--gap: 1rem;
|
||||
--space: 2rem;
|
||||
display: grid;
|
||||
grid-auto-rows: min-content;
|
||||
gap: var(--gap);
|
||||
padding-top: var(--space);
|
||||
padding-bottom: var(--space);
|
||||
}
|
||||
|
||||
@media print, screen and (min-width: 640px) {
|
||||
.remix__page {
|
||||
--gap: 2rem;
|
||||
grid-auto-rows: unset;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (min-width: 1024px) {
|
||||
.remix__page {
|
||||
--gap: 4rem;
|
||||
}
|
||||
}
|
||||
|
||||
.remix__page > main > :first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.remix__page > main > :last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.remix__page > aside {
|
||||
margin: 0;
|
||||
padding: 1.5ch 2ch;
|
||||
border: solid 1px var(--color-border);
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
.remix__page > aside > :first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.remix__page > aside > :last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.remix__form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
padding: 1rem;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
.remix__form > * {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
23926
examples/remix/package-lock.json
generated
Normal file
23926
examples/remix/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -6,21 +6,22 @@
|
||||
"dev": "remix dev"
|
||||
},
|
||||
"dependencies": {
|
||||
"@remix-run/node": "^1.5.1",
|
||||
"@remix-run/react": "^1.5.1",
|
||||
"@remix-run/vercel": "^1.5.1",
|
||||
"@vercel/node": "^2.0.0",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2"
|
||||
"@remix-run/node": "^1.7.5",
|
||||
"@remix-run/react": "^1.7.5",
|
||||
"@remix-run/vercel": "^1.7.5",
|
||||
"@vercel/analytics": "^0.1.3",
|
||||
"@vercel/node": "^2.4.4",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@remix-run/dev": "^1.5.1",
|
||||
"@remix-run/eslint-config": "^1.5.1",
|
||||
"@remix-run/serve": "^1.5.1",
|
||||
"@types/react": "^17.0.45",
|
||||
"@types/react-dom": "^17.0.17",
|
||||
"eslint": "^8.15.0",
|
||||
"typescript": "^4.6.4"
|
||||
"@remix-run/dev": "^1.7.5",
|
||||
"@remix-run/eslint-config": "^1.7.5",
|
||||
"@remix-run/serve": "^1.7.5",
|
||||
"@types/react": "^18.0.15",
|
||||
"@types/react-dom": "^18.0.6",
|
||||
"eslint": "^8.23.1",
|
||||
"typescript": "^4.7.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
/**
|
||||
* @type {import('@remix-run/dev').AppConfig}
|
||||
*/
|
||||
/** @type {import('@remix-run/dev').AppConfig} */
|
||||
module.exports = {
|
||||
serverBuildTarget: "vercel",
|
||||
// When running locally in development mode, we use the built in remix
|
||||
|
||||
2
examples/remix/remix.env.d.ts
vendored
2
examples/remix/remix.env.d.ts
vendored
@@ -1,2 +1,2 @@
|
||||
/// <reference types="@remix-run/dev" />
|
||||
/// <reference types="@remix-run/node/globals" />
|
||||
/// <reference types="@remix-run/node" />
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import * as build from "@remix-run/dev/server-build";
|
||||
import { createRequestHandler } from "@remix-run/vercel";
|
||||
import * as build from "@remix-run/dev/server-build";
|
||||
|
||||
export default createRequestHandler({ build, mode: process.env.NODE_ENV });
|
||||
|
||||
@@ -2,12 +2,16 @@
|
||||
"include": ["remix.env.d.ts", "**/*.ts", "**/*.tsx"],
|
||||
"compilerOptions": {
|
||||
"lib": ["DOM", "DOM.Iterable", "ES2019"],
|
||||
"isolatedModules": true,
|
||||
"esModuleInterop": true,
|
||||
"jsx": "react-jsx",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"target": "ES2019",
|
||||
"strict": true,
|
||||
"allowJs": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"~/*": ["./app/*"]
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user