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

feat:simplify route file #81

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

Xy2002
Copy link
Contributor

@Xy2002 Xy2002 commented Dec 24, 2024

Integrated router generation plug-in and configuration support, and implemented the function of simplifying routing files

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests and other checks with pnpm ci

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features and fix bugs should all be patch before we release 0.1.0. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

Copy link

changeset-bot bot commented Dec 24, 2024

🦋 Changeset detected

Latest commit: 199ecd8

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Xy2002
Copy link
Contributor Author

Xy2002 commented Dec 24, 2024

目前实现的效果为:

首先在 .tnfrc.ts 文件里,通过 router.routeFileSimplify 启用该功能,然后就可以直接在页面文件里,使用 export default 导出页面组件,同时 router.convention 会自动传入,作为 tanstack router 插件的配置。

移植过的 tanstack router 插件会自动在 .tnf 目录下,生成对应 pages 目录结构的中间文件,然后通过插件自动补全中间文件的内容,再对中间文件进行更改,将原本的页面组件进行导入,以替换插件自动生成的组件,完成简化路由的目的。

并且可以正常使用loader等功能,用户可以在 .tnf/pages 目录下对中间文件进行修改,页面文件变动不会直接覆盖掉生成好的中间文件。

example:

// src/pages/foo.tsx

export default function Foo() {
  return <div>Foo</div>
}

// .tnf/pages/foo.tsx

import ImportComponent from '../../src/pages/foo'
import { createFileRoute } from '@umijs/tnf/router'

export const Route = createFileRoute('/foo')({
  component: ImportComponent,
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant