How do I do the first initial (module) navigation based on some condition? #2844
-
Hi I have 3 modules, that use the same region. So I added my modules to the catalog like this, in my app.
And then I did try to navigate inside my viewmodel contructor of initialsettings, but then nothing happens as described here: #2586 So now I'm confused, where am I supposed to place the conditional code to navigate to homemodule? I've also tried adding the condition in my app like this:
But this resulted in a black screen when I ran the app, which probably has to do something with the fact that this line of code is async, as it's no longer a black screen when I comment it out.
So now I'm not sure where to add the condition, or if this is even possible? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Anything is possible. It's just code. The reason navigation isn't working in your InitialSettingsModule is because you are trying to navigate to a view in a module that hasn't been loaded yet. So, the view doesn't exist yet. You can only navigate to views in other modules if those modules have been loaded. You just have to make sure all modules that contain the views you want to navigate to are loaded first. However, it sounds like you're trying to conditionally load your modules, not views. Why not wrap that logic around the module itself and only add it if meets your condition? |
Beta Was this translation helpful? Give feedback.
-
I solved it for now by adding the condition in the MainWindowViewModel and navigating there so my app now looks like this
and my MainWindowViewModel looks like this (I'm using CommunityToolkit.Mvvm for my commands)
|
Beta Was this translation helpful? Give feedback.
Anything is possible. It's just code. The reason navigation isn't working in your InitialSettingsModule is because you are trying to navigate to a view in a module that hasn't been loaded yet. So, the view doesn't exist yet. You can only navigate to views in other modules if those modules have been loaded. You just have to make sure all modules that contain the views you want to navigate to are loaded first. However, it sounds like you're trying to conditionally load your modules, not views. Why not wrap that logic around the module itself and only add it if meets your condition?