ctron / yew-oauth2

General purpose OAuth2 component for Yew
Apache License 2.0
44 stars 17 forks source link

Router seems to work fine without the router feature #2

Closed MoonKraken closed 2 years ago

MoonKraken commented 2 years ago

Initially I enabled the router feature, and specified 'yew-router-nested' as package for yew-router.

yew-router = { version = "0.16", package = "yew-router-nested" }

I noticed the router in the example code uses conventions from the Yew v0.18 documentation.

Just for fun I tried removing the "package" attribute and removing the yew-oauth2 router feature, and using the router macros and structs from the Yew v0.19 documentation. Everything seemed to continue working as expected (my component, which is below the BrowserRouter, is able to get the OAuth2Context context as expected).

What's the backstory on why the router feature is needed and any idea why things seem to work without it?

ctron commented 2 years ago

Right, so yew 0.19 dropped the old router implementation and added a new one. However, the new one lacks a few feature, mainly the fact that you can nest routers. Which is an important feature the the stuff I am using it.

So, I did a port of the old (yew 0.18) router and made it work with yew 0.19.

yew-oauth2 doesn't need a router, however it offers additional components, which make sense in the context of using a router. those are marked with #[cfg(feature = "yew-router-nested")], like:

https://github.com/ctron/yew-oauth2/blob/8be8a7d49f5c0403d3330c51039e168d3b8718b4/src/components/redirect/mod.rs#L2-L3

If you don't need this component, then you don't need to enable the router. Also should the package feature just be a convenience feature. If you have yew-router-nested active, then this should trigger automatically (however, with feature flags and optional dependencies, I am never really sure).

I hope this explains it a bit.

MoonKraken commented 2 years ago

got it thanks ctron!