Dogstudio / highway

Highway - A Modern Javascript Transitions Manager
https://highway.js.org/
MIT License
1.43k stars 92 forks source link

Handling the loaded html before injecting it #74

Closed romainhe closed 2 years ago

romainhe commented 4 years ago

Hi ! Is there any way to manipulate the loaded html before it's injected into the current dom?

Thanks in advance for the help... I'm going crazy 😬

ThaoD5 commented 4 years ago

Hello @romainhe. What exactly are you trying to achieve ? Please give as many context as possible in order for us to give you an efficient response.

Greetings,

romainhe commented 4 years ago

Oh thx for this quick answer ! I deal with multiple components to load...

I'm setting up a navigation with several "layers". On the "Service details" page (B) I still have behind the html of the "Services" page (A), "service details" being a panel coming above.

When I'm on page A I'm loading a panel for page B, it's a separate component. So when I go from page A to B I load an html that contains A and B but I try to retrieve and inject only B. Another problem, when I go in the other direction : the highway principle is a from to, you remove from to append to, ok. But then in my case I don't want to remove the from ( B -> to A ). And so I necessarily load the content A when I do B to A, and since I don't remove the A, well that makes A A ^^

I hope that's clear enough to give you an idea. Aha!

Thx !

ThaoD5 commented 4 years ago

Why would you load A+B when going from page A to B ? Why not just B ?

romainhe commented 4 years ago

because if I load this page normally (without highway) I need html A+B, not only B :/ That's why I placed the data-router-view on component B so that it will send me B without A.

ThaoD5 commented 4 years ago

I don't understand your issue then, if you place the data-router-view at the right place on the component B you will receive the B html. So far so good.

I didn't get the "another problem" part, if you don't want to remove from, don't do it ? You just have to remove the line from.remove(); from the transition file.

romainhe commented 4 years ago

the way highway works is that the to is injected into the page in all cases. So yes I don't remove the from but the content in the to that is injected will be duplicated 🤷🏻‍♂️ and I end up with A+A

For example, there should be a "to.inject()" so that you can manipulate the to, inject it or not, etc., if necessary.

Is it clearer? 😮

ThaoD5 commented 4 years ago

That is indeed the way Highway works, the to is injected automatically otherwise you don't have a view. What I don't understand is why you have a duplicated A component. One comes from Highway adding the view automatically, the other ..?

romainhe commented 4 years ago

The other is the from I don't remove previously. Imagine a panel (the B component) opened, and you close it (page A)

What surprises me is that there is no event that can be called or extended... all the available events always take place after the injection of the to 😕

romainhe commented 4 years ago

I take the opportunity for another question, there is no feature implemented to get the referrer page when a navigation occurs, write ?

ThaoD5 commented 4 years ago

@romainhe ok I understand your issue now (finally): The way highway.js is working is not the way you expect; we actually do not support that very specific kind of scenario because of its complexity. Highway.js is a page transition library and supports all the most used cases; what you are trying to achieve here is already a more advanced routing logic. It is although an interesting case and might be interesting to have a deeper look if that scenario is a realistic setup.

About your other question, I am again not sure to understand what you mean, and what the usage of that information would be.

Thanks for your interest in Highway though !

romainhe commented 4 years ago

ahah okay, it was hard to explain. A specific event just before the injection would be perfect and would allow to play with highway on scenarios a little more complex indeed.

For my other question, detect the referrer page to execute a specific treatment if you come from a specific page ^^

ThaoD5 commented 4 years ago

I understand, but you would need to return that specific DOM you tweaked & wanted to use to somewhere also and then it gets quite crazy to add that feature ( + would need it to be added in a way that is not breaking previous versions. )

For the referrer, you can have a look here about contextual transitions

ThaoD5 commented 4 years ago

But I'll keep that in mind and have a look if I have some time in the coming weeks ;)

romainhe commented 4 years ago

Ok 👌🏼

thx

ps : if you're interested as soon as a pre-version is online I can send it to you to get a better idea of the context. @ThaoD5

romainhe commented 4 years ago

I've moved on to a "multi router-view" version if you're interested.