-
I am guessing that people are sick of the question "How do i do ViewModel first navigation in Prism". I am hoping I can give my answer at the same time as asking this common question and I can just get a nod or a "Yes". Coming from FreshMVMM to Prism MAUI we have a lot of code that does something like this
I assume we could continue doing this MyViewModel centric navigation by simply registering a custom key of "SettingsViewModel" for Navigation to "Settings" (The View) like this:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Correct. You can use the VM name as the navigation URI. To make this even better, you can introduce some extension methods into your project to make registering and navigating easier. Such as |
Beta Was this translation helpful? Give feedback.
-
As @brianlagunas indicated Prism doesn't directly support this. Navigation is by design key based. Prism uses certain defaults which results in using the View type name if no navigation key is provided. For example by default if you had: containerRegistry.RegisterForNavigation<LoginPage, LoginViewModel>(); The navigation key would be containerRegistry.RegisterForNavigation<LoginPage, LoginViewModel("Login"); Then the navigation key would be var result = await navigationService.CreateBuilder()
.AddSegment<LoginViewModel>()
.NavigateAsync(); |
Beta Was this translation helpful? Give feedback.
As @brianlagunas indicated Prism doesn't directly support this. Navigation is by design key based. Prism uses certain defaults which results in using the View type name if no navigation key is provided. For example by default if you had:
The navigation key would be
LoginPage
. However if you specified a key like:Then the navigation key would be
Login
. However with Prism.Maui's Page navigation specifically you can use the NavigationBuilder to achieve strongly typed ViewModel based navigation like: