vecty-router
vecty-router copied to clipboard
Issue using redirect - router tries to rerender component which has never been rendered
I am having problems using the redirect mechanism within the router; it seems quite basic but perhaps it's a fundamental misunderstanding on my side.
The crux of the problem is that vecty
will panic if it tries to Rerender()
a Component
which has never been rendered - I think this does not play nice with the refreshRoutes()
function in the router particularly if used with a Redirect()
.
So, if we create a couple of routes as per the example,
func (b *Body) Render() vecty.ComponentOrHTML {
return elem.Body(
router.NewRoute("/", &MainView{}, router.NewRouteOpts{ExactMatch: true}),
router.NewRoute("/blog", &Blog{}, router.NewRouteOpts{}),
)
}
and we add logic to automatically redirect from /
to /blog
, then we can easily have a scenario in which the user loads the main page /
, the redirection is triggered on the client side, which triggers refreshRoutes()
which in turn triggers a Rerender()
on the Blog Component
; however, the Blog Component
has never been rendered in the first place, so a panic occurs.
Is this a known issue or am I doing something wrong?