Alpine-Router
Alpine-Router copied to clipboard
Replace templates only for different URL tokens
Hey!
Thank you for writing this nice library. I'm not sure you still manages this project but it's actually one of the top links when you search for Alpine.js router (try "alpine js router" query in Google and see it yourself 🥇 ). I'm absolutely aware, it's not related to Alpine.js framework and it predates it, as it was mentioned here #4. Despite that, Alpine-Router can works pretty seamlessly with Alpine.js. It's also one of the few routers that supports nested routes which can be used to build nested layouts 💪 !
While playing around with the router in Alpine.js project, I noticed that navigate updates innerHTML of all <router-outlet> elements. It can cause issues with libraries / frameworks relying on mutation observer (Alpine.js, Stimulus, etc.) as it will resets parent controller's state even when the relevant part of DOM structure hasn't change (only child route changes).
This PR slightly modify the behaviour by tracking current route, and comparing it with a new one to update only relevant <router-outlet> elements.
I haven't updated tests yet as I'm not sure what's the best way to verify new logic so I would appreciate any pointers.
Hey Icmen,
I apologize it took me so long to notice your PR! I'll see if I can make some time to refresh myself on the code for this project and review your changes. It's been a long time since I've even looked at the code and I'm sure there is a lot I would like to improve! I appreciate your interest in improving the library and also informing me on its usefulness in combination with the Alpine.js framework.