我在我的應用中使用深度鏈接,並且在使用IMvxNavigationFacade
導航到視圖模型時尋找預設一些參數。深層鏈接的URL是這樣的:深度鏈接時從IMvxNavigationFacade發送MvxViewModelRequest中的新參數
myappname://深層鏈接/ toviewwithdata/navigatetoview = viewtype1 & ID = 78910
所以深層鏈接是工作和IM使用越來越導航門面組裝屬性
[assembly: MvxNavigation(typeof(RoutingFacade), @"myappname://deeplink/toviewwithdata/\?navigatetoview=(?<viewtype>viewtype1)&id=(?<id>\d{5})")]
我試圖用MvxBundle
其他參數添加到MvxViewModelRequest
但不要想我這樣做是正確的。這裏是我的導航門面:
public class RoutingFacade : IMvxNavigationFacade
{
public Task<MvxViewModelRequest> BuildViewModelRequest(string url, IDictionary<string, string> currentParameters)
{
var viewModelType = typeof(FirstViewModel);
var parameters = new MvxBundle();
try
{
// TODO: Update this to handle different view types and add error handling
if (currentParameters != null)
{
Debug.WriteLine($"RoutingFacade - {currentParameters["viewtype"]}, {currentParameters["id"]}");
switch (currentParameters["viewtype"])
{
case "viewtype1":
viewModelType = typeof(FirstViewModel);
parameters.Data.Add("test", "somevalue");
break;
default:
case "viewtype2":
viewModelType = typeof(FirstViewModel);
break;
}
}
}
catch (Exception ex)
{
Debug.WriteLine($"RoutingFacade - Exception: {ex.Message}");
//TODO viewModelType = typeof(ErrorViewModel);
}
return Task.FromResult(new MvxViewModelRequest(viewModelType, parameters, null));
}
那麼我的視圖模型初始化方法
public void Init(string id, string viewtype, string test)
{
// Do stuff with parameters
}
但測試參數爲空?你如何將參數傳遞給MvxViewModelRequest?
更新:
不知道其可能從源頭這裏尋找https://github.com/MvvmCross/MvvmCross/blob/f4b2a7241054ac288a391c4c7b7a7342852e1e19/MvvmCross/Core/Core/Navigation/MvxNavigationService.cs#L122的請求參數得到從深層鏈接網址,並從BuildViewModelRequest迴歸的正則表達式設置,facadeRequest.parameterValues被忽略。