-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to refresh the whole page when changing nested route? #2
Comments
Hi rockingdice, I'm glad you like the package, you are welcome. qlevar_router/example/lib/screens/store/bottom_nav_bar.dart Lines 84 to 91 in 8c5e293
I update first the selected tab within the same widget to update the selected tab. and then navigate to selected tab to update the child for it. |
Thank you for your detailed reply with the example! I think the problem is if I use state management instead of using URL to provide params, after reloading the page the state is lost. The main problem is the missing local state, leading to inconsistent states. Not only reloading the page, but there could also be another issue: So I would try my best to avoid using local state management currently (web only). Until the flutter team officially provides a solution to that issue, what I can do is providing useful states only from URL params. For my case, I want to share the params to both the main router and the sub-router, and if the param is changed, both of them could be updated. I can get your point about avoiding unnecessary updates for better performance, but still, could there be an option (which is off by default) to update the whole page if the user wants? I think it's probably not a bad design to support more useful scenes. |
That makes sense. I had a similar case with the example and I used the state management for it.
I hope that could help |
Just an immature idea:
If shouldUpdate is true, then if the URL is matching its child node, the parent node with this option will get updated too. So in my case :
If any path is matched below /main, the /main node also gets updated. But it's just a quick fix, still too rough. Maybe a custom callback is better:
The user can decide if the node should get updated. Like comparing params changes or others. Mostly based on the URLs:
Because my PageMain widget uses the id param, it should update when there's one in the params. |
my problem is with the word for example in the PageMain you can do router.onChildCalled = (child){
if(child.path == '/app/edit/:id'){
setState(()[
selectedChild = 'Edit';
})
}
} something like that what I have in mind |
Seems great! Your way is better. Then the widget won't be recreated, it will be updated conditionally. |
So you can now upgrade to 0.3.4 and replace
the selected tab will be correct (if it doesn't work please clear the cash in your browser and try again) qlevar_router/example/lib/screens/store/bottom_nav_bar.dart Lines 61 to 69 in 8fa9bce
I hope this fixes your problem 😄 |
@SchabanBo I met another problem like this one so I will not make another issue: Is it possible to refresh the page if navigating to the same route? The logs are:
So I guess the page will not refresh if the route is the same. The scenario is: If I click on a link from a menu, I sometimes want to refresh the page state (Like requesting again to get the latest info from the server). |
My routes are organized like this:
From my understanding,
'/main' is responsible for building the PageMain widget, while its nested routes are responsible for building Inner Widgets.
So if I change the
:id
in the nested URL, the inner widgets get updated, but the PageMain won't.What I want is to make PageMain also update when the nested URL changes.
I'll try to explain this with an example:
If I navigate from
'/main/apps'
to'/main/app/1'
,The
PageAppManage
can switch toPageAppDashboard
correctly.But
PageMain
won't get updated because it is not a part of the nested router, it's the parent router of it.I can get the param
:id
within PageMain, but the page won't update if I change the param.PageMain still needs to be updated in my case, like highlighting the selected item from the menu or change the index of a combo box in the PageMain.
I also thought it could be done not to use the nested route, but it would make the route tree unorganized - the routes are all on the same level, and I have to make each route use PageMain and handle the inner pages accordingly.
BTW, I really appreciate your work on this package. It makes the navigation much much easier than the official one. Thank you!
The text was updated successfully, but these errors were encountered: