Child routers: render another location with the parent's history

Đang mở
#8,820 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
react, typescript
Lĩnh vực
frontend

Hướng nghiên cứu

Read the prototype linked in the issue, then inspect router.ts and the Transitioner guards it describes. The proposal also calls for tests and a stack-pages example; compare those with the prototype to define the API and behavior. Done means child routers share parent history and blockers, keep navigation relative to the child location, and avoid URL changes and extra global listeners.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

We keep pages mounted under sliding panels: any page can open on top of the current one with stackNavigate('/foo/p1'), and the page below keeps its exact state (form input, filters, scroll). The URL is always the top page, the pages below live in history state.

Right now the only way to do this with TanStack Router is a createRouter per layer plus a hand-written RouterHistory that's fixed to one location. It works, but every router adds scroll restoration listeners that are never removed (#8775), every Transitioner canonicalizes and replaces the URL on mount, self.__TSR_ROUTER__ gets overwritten, and the custom history has to implement _getBlockers/notify.

Proposal, a parent option:

const child = createRouter({ ...router.options, parent: router, location: '/foo/p1' })
child.setLocation('/foo/p2')

A child uses the parent's history and blockers, hands its navigations to the parent (relative to still resolves against the child's location), never reads or writes the URL, adds no global listeners and doesn't touch __TSR_ROUTER__. Hooks stay the same, each child has its own RouterProvider. Out of scope for now: sharing committed match data, SSR, transitions.

I made a prototype to see how it looks: compare. It's ~45 lines in router.ts plus a 2-line guard in each Transitioner, with tests and a stack-pages example. In our app it removes our whole custom layer history.

Is parent an OK shape, or would you prefer something like a free createChildRouter(router, { location })? Happy to turn it into a PR once the API is agreed.

Ngôn ngữ chính
TypeScript
Star
15.3k
Fork
1.9k
Merge trung bình
1 ngày 5 giờ
Pull request đã merge (30 ngày)
46

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TanStack/router

Tất cả issue của TanStack/router

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.