简体   繁体   中英

LaunchUriAsync does not navigate to the correct uri

I need to navigate to an internet page within my metro application. My url is (sample) 'http://www.foo.com/#/foo'. The issue is that LaunchUriAsync cut the url to 'http://www.foo.com'.

try
{
    Uri uri = new Uri(item.UriCode); 
    await Launcher.LaunchUriAsync(uri);
}
catch (Exception exception)
{
    //TODO
}

Where am I wrong ? Regards.

Update :

I precise that uri = http://www.foo.com/#/foo . So the issue comes from LaunchUriAsync .

I tried with the same code just hardcoding the uri that you mentioned Please check the code below :

    /// <summary>
    /// Invoked when this page is about to be displayed in a Frame.
    /// </summary>
    /// <param name="e">Event data that describes how this page was reached.  The Parameter
    /// property is typically used to configure the page.</param>
    protected async override void OnNavigatedTo(NavigationEventArgs e)
    {
        try
        {
            Uri uri = new Uri("http://www.foo.com/#/foo");
            await Launcher.LaunchUriAsync(uri);
        }
        catch (Exception exception)
        {
            //TODO
        }
    }

The output is shown below

具有相应URL的启动器测试

i think there's some other problem. May be with the item.UriCode line please check .

I think it is difficult to diagnose what is actually wrong from your example.

It appears you are trying to navigate to an anchor within a web page, but doing it with incorrect syntax / pointing to a non-existent anchor. However, your example linked page doesn't seem to contain a navigable anchor.

Assuming that this is actually what you are trying to achieve, try the following example, and you will see that navigation works as expected

Launcher.LaunchUriAsync(new Uri("http://www.hypergurl.com/anchors.html#bottom"));

If this isn't what you are trying to achieve, I would suggest that the presence of the # character in the URI is being interpretted as an anchor reference by IE and that's why you aren't getting the result you require.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM