I'm currently developing a app in which we have a feature called "tips" which are essentially microblogs. In these blogs which are html based you can link to other "Content" that exists on our app through ordinary hyperlinks.
The app is set up to open the url scheme of these links and all platforms have their own code to funnel the new uri into the xamarin forms app via the MessagingCenter which has a subcriber inside of the App class like this:
MessagingCenter.Subscribe(Current, DoshiMessages.NewUri, async (Application app, string uri) =>
{
var result = await HandleUriNavAsync(uri);
if (!result)
await Container.Resolve<IUserDialogs>().AlertAsync("Link was invalid");
});
Which calls:
private async Task<bool> HandleUriNavAsync(string uri)
{
if (uri == null)
return false;
await NavigationService.NavigateAsync(new Uri(uri, UriKind.Absolute));
return true;
}
Now this works fine with absolute uri's but if i change it to
//Example: uri = www.example.com/main/nav/test?userid=0
private async Task<bool> HandleUriNavAsync(string uri)
{
if (uri == null)
return false;
//Example: relative = test?userid=0
var relative = uri.Split('/').Last();
await NavigationService.NavigateAsync(new Uri(relative, UriKind.Relative));
return true;
}
Navigation never triggers but no exceptions are thrown and the task finishes successfully(I have checked). Note the above code is executed while the app is already running and already has active viewmodels.
Is there something obvious I'm doing wrong and is there a better way of achieving this?
Cheers!