dsuryd / dotNetify

Simple, lightweight, yet powerful way to build real-time web apps.
https://dotnetify.net
Other
1.17k stars 164 forks source link

Props to Template on vm.onRouteEnter #235

Closed verystack closed 4 years ago

verystack commented 4 years ago

Hi Dicky,

Was wondering if there was a prescribed way in Dotnetify or pattern you'd recommend for passing props to the vm.onRouteEnter template target?

One view that I'm working with requires some props to be passed in from the AppLayout view. Will just suppress the router warning and roll my own templating if necessary.

Best regards

dsuryd commented 4 years ago

There's the URL pattern matching as in the "Book Store" example, e.g. "book(/:title)". This is the best way to pass arguments to a view, because navigating the URL directly will work.

If you really need to pass objects between views, use an intermediary data cache: the AppLayout view sets it before it's routed, then the new view gets it to initialize itself. This intermediary can be as simple as a singleton to something like Redux store.