Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/basename #4459

Closed
wants to merge 12 commits into from
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@
- yomeshgupta
- youbicode
- youngvform
- yracnet
- zachdtaylor
- zainfathoni
- zhe
Expand Down
5 changes: 5 additions & 0 deletions docs/components/form.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ title: Form

<docs-success>Watch the <a href="https://www.youtube.com/playlist?list=PLXoynULbYuEDG2wBFSZ66b85EIspy3fy6">📼 Remix Singles</a>: <a href="https://www.youtube.com/watch?v=Iv25HAHaFDs&list=PLXoynULbYuEDG2wBFSZ66b85EIspy3fy6">Data Mutations with Form + action</a>, <a href="https://www.youtube.com/watch?v=w2i-9cYxSdc&list=PLXoynULbYuEDG2wBFSZ66b85EIspy3fy6">Multiple Forms and Single Button Mutations</a> and <a href="https://www.youtube.com/watch?v=bMLej7bg5Zo&list=PLXoynULbYuEDG2wBFSZ66b85EIspy3fy6">Clearing Inputs After Form Submissions</a></docs-success>

<docs-info>This component is simply a re-export of [React Router's `Form`][rr-form].</docs-info>

The `<Form>` component is a declarative way to perform data mutations: creating, updating, and deleting data. While it might be a mind-shift to think about these tasks as "navigation", it's how the web has handled mutations since before JavaScript was created!

```tsx
Expand Down Expand Up @@ -92,6 +94,8 @@ When the `action` prop is omitted, `<Form>` and `<form>` will sometimes call dif
- `<form>` uses the current URL as the default which can lead to surprising results: forms inside parent routes will post to the child action if you're at the child's URL and the parents action when you're at the parent's URL. This means as the user navigates, the form's behavior changes.
- `<Form>` will always post to the route's action, independent of the URL. A form in a parent route will always post to the parent, even if you're at the child's URL.

For more information and usage, please refer to the [React Router `Form` docs][rr-form].

See also:

- [`useTransition`][usetransition]
Expand All @@ -103,3 +107,4 @@ See also:
[useactiondata]: ../hooks/use-action-data
[usesubmit]: ../hooks/use-submit
[http-verb]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
[rr-form]: https://reactrouter.com/components/form
2 changes: 1 addition & 1 deletion docs/components/outlet.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ title: Outlet

# `<Outlet>`

Re-export of [React Router Outlet][rr-outlet].
This <docs-info> is simply a re-export of [React Router's `Outlet`][rr-outlet].</docs-info>

[rr-outlet]: https://reactrouter.com/components/outlet
10 changes: 10 additions & 0 deletions docs/hooks/use-async-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: useAsyncError
toc: false
---

# `useAsyncError`

<docs-info>This hook is simply a re-export of [React Router's `useAsyncError`][rr-useassyncerror].</docs-info>

[rr-useassyncerror]: https://reactrouter.com/hooks/use-async-error
10 changes: 10 additions & 0 deletions docs/hooks/use-async-value.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: useAsyncValue
toc: false
---

# `useAsyncValue`

<docs-info>This hook is simply a re-export of [React Router's `useAsyncValue`][rr-useassyncvalue].</docs-info>

[rr-useassyncvalue]: https://reactrouter.com/hooks/use-async-value
7 changes: 7 additions & 0 deletions docs/hooks/use-before-unload.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
---
title: useBeforeUnload
toc: false
---

# `useBeforeUnload`

<docs-info>This hook is simply a re-export of [React Router's `useBeforeUnload`][rr-usebeforeunload].</docs-info>

This hook is just a helper around `window.onbeforeunload`.

When users click links to pages they haven't visited yet, Remix loads the code-split modules for that page. If you deploy in the middle of a user's session, and you or your host removes the old files from the server (many do 😭), then Remix's requests for those modules will fail. Remix recovers by automatically reloading the browser at the new URL. This should start over from the server with the latest version of your application. Most of the time this works out great, and user doesn't even know anything happened.
Expand Down Expand Up @@ -35,3 +38,7 @@ function SomeForm() {
return <>{/*... */}</>;
}
```

For more information and usage, please refer to the [React Router `useBeforeUnload` docs][rr-usebeforeunload].

[rr-usebeforeunload]: https://reactrouter.com/hooks/use-before-unload
1 change: 1 addition & 0 deletions docs/hooks/use-fetcher.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: useFetcher
toc: false
---

# `useFetcher`
Expand Down
6 changes: 6 additions & 0 deletions docs/hooks/use-form-action.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ title: useFormAction

# `useFormAction`

<docs-info>This hook is simply a re-export of [React Router's `useFormAction`][rr-useformaction].</docs-info>

Resolves the value of a `<form action>` attribute using React Router's relative paths. This can be useful when computing the correct action for a `<button formAction>`, for example, when a `<button>` changes the action of its `<form>`.

```tsx
Expand All @@ -20,3 +22,7 @@ function SomeComponent() {
```

(Yes, HTML buttons can change the action of their form!)

For more information and usage, please refer to the [React Router `useFormAction` docs][rr-useformaction].

[rr-useformaction]: https://reactrouter.com/hooks/use-form-action
10 changes: 10 additions & 0 deletions docs/hooks/use-href.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: useHref
toc: false
---

# `useHref`

<docs-info>This hook is simply a re-export of [React Router's `useHref`][rr-usehref].</docs-info>

[rr-usehref]: https://reactrouter.com/hooks/use-href
10 changes: 10 additions & 0 deletions docs/hooks/use-location.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: useLocation
toc: false
---

# `useLocation`

<docs-info>This hook is simply a re-export of [React Router's `useLocation`][rr-uselocation].</docs-info>

[rr-uselocation]: https://reactrouter.com/hooks/use-location
10 changes: 10 additions & 0 deletions docs/hooks/use-navigate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: useNavigate
toc: false
---

# `useNavigate`

<docs-info>This hook is simply a re-export of [React Router's `useNavigate`][rr-usenavigate].</docs-info>

[rr-usenavigate]: https://reactrouter.com/hooks/use-navigate
10 changes: 10 additions & 0 deletions docs/hooks/use-navigation-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: useNavigationType
toc: false
---

# `useNavigationType`

<docs-info>This hook is simply a re-export of [React Router's `useNavigationType`][rr-usenavigationtype].</docs-info>

[rr-usenavigationtype]: https://reactrouter.com/hooks/use-navigation-type
6 changes: 3 additions & 3 deletions docs/hooks/use-navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ toc: false

# `useNavigation`

This hook is simply a re-export of [React Router `useNavigation`][rr-usenavigation].
<docs-info>This hook is simply a re-export of [React Router `useNavigation`][rr-usenavigation].</docs-info>

```tsx
import { useNavigation } from "@remix-run/react";
Expand All @@ -20,6 +20,6 @@ function SomeComponent() {
}
```

For information and usage, please refer to the [React Router `useNavigation` docs][rr-usenavigation].
For more information and usage, please refer to the [React Router `useNavigation` docs][rr-usenavigation].

[rr-usenavigation]: https://reactrouter.com/en/main/hooks/use-navigation
[rr-usenavigation]: https://reactrouter.com/hooks/use-navigation
10 changes: 10 additions & 0 deletions docs/hooks/use-outlet-context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: useOutletContext
toc: false
---

# `useOutletContext`

<docs-info>This hook is simply a re-export of [React Router's `useOutletContext`][rr-useoutletcontext].</docs-info>

[rr-useoutletcontext]: https://reactrouter.com/hooks/use-outlet-context
10 changes: 10 additions & 0 deletions docs/hooks/use-outlet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: useOutlet
toc: false
---

# `useOutlet`

<docs-info>This hook is simply a re-export of [React Router's `useOutlet`][rr-useoutlet].</docs-info>

[rr-useoutlet]: https://reactrouter.com/hooks/use-outlet
10 changes: 10 additions & 0 deletions docs/hooks/use-params.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: useParams
toc: false
---

# `useParams`

<docs-info>This hook is simply a re-export of [React Router's `useParams`][rr-useparams].</docs-info>

[rr-useparams]: https://reactrouter.com/hooks/use-params
10 changes: 10 additions & 0 deletions docs/hooks/use-resolved-path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: useResolvedPath
toc: false
---

# `useResolvedPath`

<docs-info>This hook is simply a re-export of [React Router's `useResolvedPath`][rr-useresolvedpath].</docs-info>

[rr-useresolvedpath]: https://reactrouter.com/hooks/use-resolved-path
6 changes: 4 additions & 2 deletions docs/hooks/use-revalidator.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ title: useRevalidator

# `useRevalidator`

<docs-info>This hook is simply a re-export of [React Router's `useRevalidator`][rr-userevalidator].</docs-info>

This hook allows you to revalidate the data for any reason. React Router automatically revalidates the data after actions are called, but you may want to revalidate for other reasons like when focus returns to the window.

```jsx
Expand All @@ -24,6 +26,6 @@ function WindowFocusRevalidator() {
}
```

For more information see the [React Router `useRevalidator` docs][rr-userevalidator]
For more information and usage, please refer to the [React Router `useRevalidator` docs][rr-userevalidator].

[rr-userevalidator]: https://reactrouter.com/en/main/hooks/use-revalidator
[rr-userevalidator]: https://reactrouter.com/hooks/use-revalidator
10 changes: 10 additions & 0 deletions docs/hooks/use-route-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: useRouteError
toc: false
---

# `useRouteError`

<docs-info>This hook is simply a re-export of [React Router's `useRouteError`][rr-userouteerror].</docs-info>

[rr-userouteerror]: https://reactrouter.com/hooks/use-route-error
8 changes: 5 additions & 3 deletions docs/hooks/use-route-loader-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ toc: false

# `useRouteLoaderData`

This hook is simply a re-export of [React Router `useRouteLoaderData`][userouteloaderdata]. Pass in a route ID and it will return the loader data for that route.
<docs-info>This hook is simply a re-export of [React Router `useRouteLoaderData`][rr-userouteloaderdata].</docs-info>

Pass in a route ID and it will return the loader data for that route.

```tsx
import { useRouteLoaderData } from "@remix-run/react";
Expand All @@ -23,6 +25,6 @@ Remix creates the route IDs automatically. They are simply the path of the route
| `app/routes/teams.tsx` | `"routes/teams"` |
| `app/routes/teams.$id.jsx` | `"routes/teams.$id"` |

For more information and usage, please refer to the [React Router `useRouteLoaderData` docs][userouteloaderdata].
For more information and usage, please refer to the [React Router `useRouteLoaderData` docs][rr-userouteloaderdata].

[userouteloaderdata]: https://reactrouter.com/en/main/hooks/use-route-loader-data
[rr-userouteloaderdata]: https://reactrouter.com/hooks/use-route-loader-data
10 changes: 10 additions & 0 deletions docs/hooks/use-search-params.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: useSearchParams
toc: false
---

# `useSearchParams`

<docs-info>This hook is simply a re-export of [React Router's `useSearchParams`][rr-usesearchparams].</docs-info>

[rr-usesearchparams]: https://reactrouter.com/hooks/use-search-params
6 changes: 6 additions & 0 deletions docs/hooks/use-submit.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ title: useSubmit

# `useSubmit`

<docs-info>This hook is simply a re-export of [React Router's `useSubmit`][rr-usesubmit].</docs-info>

Returns the function that may be used to submit a `<form>` (or some raw `FormData`) to the server using the same process that `<Form>` uses internally `onSubmit`. If you're familiar with React Router's `useNavigate`, you can think about this as the same thing but for `<Form>` instead of `<Link>`.

This is useful whenever you need to programmatically submit a form. For example, you may wish to save a user preferences form whenever any field changes.
Expand Down Expand Up @@ -68,3 +70,7 @@ function useSessionTimeout() {
}, [submit, transition]);
}
```

For more information and usage, please refer to the [React Router `useSubmit` docs][rr-usesubmit].

[rr-usesubmit]: https://reactrouter.com/hooks/use-submit
1 change: 1 addition & 0 deletions packages/remix-dev/__tests__/readConfig-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe("readConfig", () => {
"path": "",
},
},
"serverBasename": "",
"serverBuildPath": Any<String>,
"serverBuildTarget": undefined,
"serverBuildTargetEntryModule": "export * from \\"@remix-run/dev/server-build\\";",
Expand Down
26 changes: 24 additions & 2 deletions packages/remix-dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ export interface AppConfig {
*/
serverBuildPath?: string;

/**
* Server Basename is a location path for app deploy on server.
*
* If omitted, the default location path is / (root directory)
* {@link ServerConfig.serverBasename}.
*/
serverBasename?: string;

/**
* The path to the browser build, relative to `remix.config.js`. Defaults to
* "public/build".
Expand Down Expand Up @@ -219,6 +227,14 @@ export interface RemixConfig {
*/
serverBuildPath: string;

/**
* Server Basename is a location path for app deploy on server.
*
* If omitted, the default location path is / (root directory)
* {@link ServerConfig.serverBasename}.
*/
serverBasename?: string;

/**
* The absolute path to the assets build directory.
*/
Expand Down Expand Up @@ -340,6 +356,7 @@ export async function readConfig(
}
}

let serverBasename = appConfig.serverBasename || "";
let customServerEntryPoint = appConfig.server;
let serverBuildTarget: ServerBuildTarget | undefined =
appConfig.serverBuildTarget;
Expand Down Expand Up @@ -438,7 +455,11 @@ export async function readConfig(
}

let routes: RouteManifest = {
root: { path: "", id: "root", file: rootRouteFile },
root: {
path: serverBasename,
id: "root",
file: rootRouteFile,
},
};

let routesConvention = appConfig.future?.v2_routeConvention
Expand Down Expand Up @@ -519,7 +540,8 @@ export async function readConfig(
devServerBroadcastDelay,
assetsBuildDirectory: absoluteAssetsBuildDirectory,
relativeAssetsBuildDirectory: assetsBuildDirectory,
publicPath,
serverBasename,
publicPath: path.join(serverBasename, publicPath).replace(/\\/g, "/"),
rootDirectory,
routes,
serverBuildPath,
Expand Down
9 changes: 6 additions & 3 deletions packages/remix-dev/devServer/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ export async function serve(
app.use(
createApp(
config.serverBuildPath,
mode,
config.publicPath,
config.assetsBuildDirectory
{
mode,
basename: config.serverBasename,
publicPath: config.publicPath,
assetsBuildDirectory: config.assetsBuildDirectory
}
)
);

Expand Down
2 changes: 1 addition & 1 deletion packages/remix-express/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function createRemixRequest(
res: express.Response
): NodeRequest {
let origin = `${req.protocol}://${req.get("host")}`;
let url = new URL(req.url, origin);
let url = new URL(req.originalUrl, origin);

// Abort action/loaders once we can no longer write a response
let controller = new NodeAbortController();
Expand Down
Loading