hyperstack-org / hyperstack-org/hyperstack

add ability to mount a component from a router

未关闭
#287 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
enhancement
主要语言
JavaScript
星标
538
派生
41
PR 合并指标
30 天内没有已合并 PR

描述

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.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。