Repository navigation
Replies: 5 comments 2 replies
|
Thank you! When it comes to the scrolling it should work out-of-the-box due to this line. This is how the navigation action looks like: public void Go()
{
Location(Url.Action("Index", "MyController"));
}And BTW, also the JS invocation should work, when you do it like that: <button type="button" hydro-on:click="@(() => Model.Client.Invoke("alert()"))">
Show alert
</button>Let me know if it worked. |
|
Hi When I "navigate using Hydro" in this specific case it's the component that rebuilds itself with a new screen, without using JS invocation is not really working from inside Hydro. Why?
is translated to
this works, and we could avoid writing Once we replace this code with it shows that the JS is not executed in browser, when the wrapper code is executed on server. Maybe we could fix this like this: when
This could also fix #49 the "Maybe hydro should have some kind of mechanism for executing javascript as part of the request". At the same time I just found a workaround, thanks to your tip at this line. I have added some "native events", to be consumed in JS to respond to Hydro activities. What I have so far: This way I can scroll to top when I get a nice Example of native events incoming:
I could create a PR if this is to interest. |
|
Thanks for a nice investigation. Those native Hydro events in JS look cool! There is something a bit similar that might be helpful here without additional implementation. You can dispatch an event in Hydro action and listen to it later in JS. Event: public record ClientResetScroll;In hydro action: DispatchGlobal(new ClientResetScroll());In your JS file: document.addEventListener('global:ClientResetScroll', function () {
window.scrollTo(0, 0);
});So basically all the global events dispatched in Hydro are also dispatched on the Another thing that might be helpful here is AlpineJs' init directive: The following code you can put to your page and once it's loaded, the code in x-init will be executed once. <div x-init="window.scrollTo(0, 0)"></div>Such snippets can be implemented later also as Hydro views, so you might use them in the code like: <scroll-to-top />Was it helpful? |
|
I wrote an implementation for this, as I was really needing it. :) Overall I'm super happy with this, I can now order JS execution from inside the server component code. Also solves that #49 "can't find a way to execute javascript from .net". Explanation: Added new We have 2 main channels to render/deliver component data: static and online. A. Online is used when we update the component, here we can send component-related data (scripts in this case) with request headers. The B. Static is used when the component is delivered along with the page content, would it be the initial page load or a partial page content load with Location(). The Inside the hydro.js:
On server: inside the What is also nice here, I think, is that we enhance the channel of communication server=>client to be used for more similar cases should they be needed. |
|
Fixed |

Uh oh!
There was an error while loading. Please reload this page.
First would like to thank the author for this awesome library, it feels like fresh air to start coding with Blazor-like tech inside an mvc app.
I'm trying to invoke JS to scroll to top of the page after I navigated (using Hydro) without page reload to another section.
In the docs I don't see much.
Tried to use
Client.Invoke("onAfterNavigated()");here and there but no luck, well, nothing happens. Maybe this works in Razor Pages but not for Controllers with views?A workaround could be to somehow detect in DOM that it was a Hydro navigation event. If I attach anobserver with JS I'm getting all the DOM changes coming not only from Hydro..
All reactions