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

请问如何实现这种布局嵌套的要求? #6584

Closed
ochive opened this issue Oct 14, 2023 · 2 comments
Closed

请问如何实现这种布局嵌套的要求? #6584

ochive opened this issue Oct 14, 2023 · 2 comments

Comments

@ochive
Copy link

ochive commented Oct 14, 2023

目录:

-- pages 
          |
          layout.tsx                       全局布局组件. 充当视图入口, 配置国际化, 主题
          basicLayout.tsx              业务页面的统一布局.   首页布局.
          |
          session                         
                     |
                     layout.tsx             登录, 注册等匿名页面的简单布局
                     index.tsx              希望此处的布局为   "layout" > "layout"
          |
          system
                    |
                    index.tsx                希望system和business等业务页面布局为:"layout" > "basicLayout"
          |
          business
                    |
                    index.tsx

我是很喜欢约定式路由的, 但似乎无法实现上面的布局需求.
如果将system, business, basicLayout.tsx再放到一层目录中是可以, 但似乎不够优雅. 而且现有代码已经很多, 此时不敢随便动目录了.
请问在defineRoutes中如何配置, 这个折腾半天, 官网文档没看懂.

@ClarkXia
Copy link
Collaborator

ClarkXia commented Oct 16, 2023

目前基于约定的情况下如果路由间的布局组件是有差异的,可以参考以下两种思路:

  1. 集中式管理,所有 Provider 和布局的渲染统一收敛至 pages/layout.tsx,内部通过当前路径信息决定渲染逻辑
  2. 各自维护管理,pages/layout.tsx 仅用于 Provider 配置,在 pages/* 目录下均增加 layout 文件,如果布局逻辑相同可以增加 components/basicLayout.tsx 文件,然后在约定式布局组件中按需引入

@ochive
Copy link
Author

ochive commented Oct 16, 2023

谢谢你的分析, 我决定尝试下第二种思路.
目前我是第一种, 整个项目只有一个layout, 里面太多的if...else. 😅
感觉第二种按需引入basicLayout更灵活. 且各业务视图目录的layout如无自定义需求, 只是把basicLayout包装下, 逻辑也比较清晰.

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

No branches or pull requests

2 participants