hyperstack-org / hyperstack-org/hyperstack

add ability to mount a component from a router

Đang mở
#287 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
enhancement
Ngôn ngữ chính
JavaScript
Star
538
Fork
41
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

If a component is mounted from a router, then it won't work unless it is actually mounted from that router.

This makes hyper-specs `mount` method not work directly.

Instead you have to create a wrapper component that looks like this:

```ruby
class RouteToProfile < HyperComponent
include Hyperstack::Router
param :id
render do
Switch do
Route('/profile/:id', mounts: UserProfile)
Route('/') { Redirect("/profile/#{id}") }
end
end
end
```

then you can mount `RouteToProfile` and pass the id.

It should be possible to add a `route` option to the mount method, that if present will do the above by using a predefined RouteToComponent method, that takes as parameters the component to mount, the hash of route params, and the route.

For example

```ruby
mount 'Profile', {id: 1}, route: '/profile/:id'
```

would translate to
```ruby
mount 'RouteToComponent', route: '/profile/:id', params: {id: 1}
```
which would dynamically figure everything out.

In the meantime the work around is to follow the pattern above.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

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.