文档了解模型

项目结构

Nexy 项目中的每个文件都有一项工作,其去向取决于路由器:src/routes/ 用于基于文件的路由,src/apps/ 用于模块化路由器。

顶级

my-app/
src/
routes/every file is a route
index.nexy→ /
layout.nexyshared layout, not a route
api/hello.py→ /api/hello
components/imported components (a convention, not enforced)
globale.cssglobal styles (created by nexy new)
public/served at /
nexyconfig.pyproject configuration
pyproject.toml
package.jsononly with a client framework
vite.config.tsonly with a client framework
__nexy__/build output - generated, never edited

要选择文件夹,请询问文件是什么:

  • 浏览器可以打开的东西 - 路线:src/routes/。
  • 多个路线使用的片段 - 组件或模块:src/components/、src/。
  • 文件按原样使用 - public/。
  • 生成 - __nexy__/;永远不要编辑它。
my-app/
src/
apps/controllers, modules and their views
app_module.pythe root module, given to useRouter
app_controller.py
app_view.nexya view a controller returns
layout.nexythe frame the controllers pass their view to
users/one folder per feature: controller, module, service, model
components/imported components (a convention, not enforced)
globale.cssglobal styles (created by nexy new)
public/served at /
nexyconfig.pyproject configuration: useRouter = AppModule
pyproject.toml
package.jsononly with a client framework
vite.config.tsonly with a client framework
__nexy__/build output - generated, never edited

要选择文件夹,请询问文件是什么:

  • URL - src/apps/ 中控制器的方法,由其模块注册。
  • 页面 - 其控制器旁边的 .nexy 视图,以 useViews返回。
  • 被多个视图使用的片段 - src/components/。
  • 文件按原样使用 - public/。
  • 生成 - __nexy__/;永远不要编辑它。
my-app/
src/
legacy/the FastAPI router you include
api.pyrouter = APIRouter(prefix="/api")
routes/pages and route files, served next to it
index.nexy→ /
components/imported components (a convention, not enforced)
globale.cssglobal styles (created by nexy new)
public/served at /
nexyconfig.pyproject configuration: useRouter = router
pyproject.toml
package.jsononly with a client framework
vite.config.tsonly with a client framework
__nexy__/build output - generated, never edited

要选择文件夹,请询问文件是什么:

  • 包含的应用程序 的路线 - 它已经在此处,这里 src/legacy/。
  • 新页面或路由 - src/routes/,位于所包含的路由器旁边。
  • 文件按原样使用 - public/。
  • 生成 - __nexy__/;永远不要编辑它。

src/routes/

除了下面的保留名称之外,每个文件都成为一条路由。文件路径减去扩展名就是 URL - 请参阅基于文件的路由。

文件 角色
layout.nexy 包装兄弟页面和子页面
errors.nexy 目录 500 页
notfound.nexy 目录的 404 页面
dependencies.py 目录的共享 FastAPI 依赖项
__init__.py Python 封装标记
loading.nexy 保留 - 从路由中排除,但它还没有运行时效果

每个页面名称也存在于每个框架中。配置 react() 后,layout.jsx 和 layout.tsx 被保留,与 layout.nexy完全相同。这些列表是在 nexy/core/config.py(LAYOUT_FILE_NAMES、ERROR_FILE_NAMES、NOTFOUND_FILE_NAMES、LOADING_FILE_NAMES)中构建的。

src/apps/

控制器应答 URL,模块将控制器和提供者分组,根模块通过 nexyconfig.py 中的 useRouter 挂载:

src/apps/app_controller.py
from nexy.decorators import Controllerfrom nexy.hooks import useViews LAYOUT = "src/apps/layout.nexy"  @Controller()class AppController:    async def get(self):        return useViews(LAYOUT, context={"children": useViews("src/apps/app_view.nexy")})
src/apps/app_module.py
from nexy.decorators import Module from .app_controller import AppController  @Module()class AppModule:    controllers = [AppController]
nexyconfig.py
from nexy.core.models import NexyConfigModel from src.apps.app_module import AppModule  class NexyConfig(NexyConfigModel):    useRouter = AppModule    useAliases = {"@": "src"}  # the views import @/components/...

src/apps/ 中的文件不是其名称的路由:只有模块的控制器列出了答案。请参阅模块化路由。

public/

这里的文件由站点根目录提供:/favicon.ico、/robots.txt、图像、字体。

__nexy__/

由 nx build 生成(以及由 nx dev 生成它所需的部分)。它包含:

  • 已编译的 .nexy 文件,作为 Python 包 (__nexy__/src/...);
  • 生成的客户端入口点(main.ts、vite.ts、*.auto.ts);
  • client/ 在 Vite 构建之后 - 资产、清单、预渲染 HTML;
  • build-cache.json。

将整个目录视为一次性目录:删除它,重建它。手动编辑它会丢失下一个版本的更改。将其添加到 .gitignore。

后续步骤

  • 配置:每个项目选项
  • 前端:Vite,样式和客户端构建

在 GitHub 上编辑

Enter 打开结果,Esc 关闭。