Description
Normally when I navigate to a URL inside my app I would use something like UriHelper
to encode the URL. But this has been replaced by the NavigationManager
.
I am wondering if the NavigationManager.NavigateTo
should do a UrlEncode
?
The following example code works fine:
NavigationManager.NavigateTo("/?search=some criteria | other criteria");
This will let the application navigate properly. The URL that comes out in the browser will look like this:
/?search=some%20criteria%20|%20other%20criteria
But, when I copy that URL from the browser and when I paste it into a new window, I then get the following error:
[2019-09-24T09:32:14.420Z] Error: The uris provided are invalid.
e.log @ blazor.server.js:15
blazor.server.js:1 [2019-09-24T09:32:14.421Z] Information: Connection disconnected.
blazor.server.js:1 Uncaught (in promise) Error: Invocation canceled due to the underlying connection being closed.
at e.connectionClosed (blazor.server.js:1)
at e.connection.onclose (blazor.server.js:1)
at e.stopConnection (blazor.server.js:1)
at e.transport.onclose (blazor.server.js:1)
at e.close (blazor.server.js:1)
at e.stop (blazor.server.js:1)
at e.<anonymous> (blazor.server.js:1)
at blazor.server.js:1
at Object.next (blazor.server.js:1)
at s (blazor.server.js:1)
This is because the piped character is in the URL. This only fails when pasting the URL directly into the browser.
The same thing happends for a few other characters like curly brackets.
I am not sure if this is a bug? Or am I responsible to do a url encoding before passing the URL to the NavigateTo
method?
If so, what should I use, siince the UriHelper
has been replaced?
Right now the behaviour is not very consistent when navigation through codes works fine, untill you copy paste the URL in the browser.