Skip to content

Add support for +types imports with React Router v7 #98

@jdnichollsc

Description

@jdnichollsc

Hello folks, hope you're doing well

I'm migrating a RemixJS v2 app from a monorepo with Nx to React Router v7 with Framework mode. I was checking your examples but you don't have any example using the new types for routes as they explain here in the docs https://reactrouter.com/upgrading/remix#9-update-types-for-apploadcontext, e.g:

  • routes/home.tsx:
import { data } from 'react-router';
import type { Route } from "./+types/home"; // how can we support this generated react router types here?

export const loader = ({}: Route.LoaderArgs) => {
  return data({ message: 'Ok' }, { status: 202 });
};

export default function Home({ loaderData, actionData }: Route.ComponentProps) {
  const { message } = loaderData
}

Also, what's the best way to be able to use path alias as well? e.g from my old remixjs app:

{
  "extends": "../../tsconfig.base.json",
  "compilerOptions": {
    "paths": {
      "~/*": ["app/*"],
      "@projectx/models": ["../../libs/models/src/index.ts"],
      "@projectx/email": ["../../libs/backend/email/src/index.ts"],
    },
    // Remix takes care of building everything in `remix build`.
    "noEmit": true
  },
  "include": [],
  "files": [],
  "references": [
    {
      "path": "./tsconfig.app.json"
    }
  ]
}

This is the repo of this old remixjs v2 app: https://github.com/proyecto26/projectx/blob/develop/apps/web/tsconfig.json#L18

Any help is really appreciated! <3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions