Say if I want to add the source of an image and I rely on IntelliSense to complete the directory for me, it adds a ~ at the beginning of the file path. This will not load the file, and if you remove the ~ it works. I believe this was an issue over a year ago, however it was closed, perhaps it was solved, but IntelliSense itself still adds the ~ to the beginning for users.
Steps to reproduce the behavior:



That it shouldn't have the ~ added with IntelliSense
This is what works

Sorry if it's already been reported, couldn't find it anywhere
This is for Blazor, just edited post
Thanks for contacting us, @salmanmkc.
@jodavis can you please handle this one? The ~/ should be missing for .razor files after completion.
Example of an expected tag:
<img src="somedir/file.png" />
Note how the value does not start with either ~/ or /, since the URLs should be base-relative, not root-relative.
We can take a look at this.
@mkArtakMSFT (or others) - How does Blazor handle URLs in layout pages? The reason we default to app-relative ("~/") URLs is because we can't always predict what the base URL of a file is going to be, especially in a layout page where the base URL changes depending on the page using the layout, or in a routing situation where "localhost/" and "localhost/Index" can refer to the same page.
In a sample app, I see something is setting <base href="/" /> in the page. Is that configurable, or is it guaranteed to be there in all Blazor apps?
In a sample app, I see something is setting
<base href="/" />in the page. Is that configurable, or is it guaranteed to be there in all Blazor apps?
It is there in the templates, and it's the developer's responsibility to keep it there and/or update it to whatever base URL they are using. Since .razor files are primarily for use in SPAs, base-relative routing is standard everywhere in the framework.
Thanks for contacting us, @salmanmkc.
@jodavis can you please handle this one? The~/should be missing for.razorfiles after completion.
No problem! Thanks for getting back so soon ☺
I see it now. I don't know why I didn't find the _Host.cshtml file when I searched earlier.
That makes things a little complicated for the editor. From the context of a component, we don't really know what page the component will be hosted in, so we can't really know what the base URL will be when completing a URL.
We could assume that the base maps to the wwwroot folder, and make URLs relative to that. If the user customizes their base URL, then the editor will start inserting the wrong URLs. Would that be a reasonable compromise? How common do you think it will be for users to customize their base URL?
We could assume that the base maps to the wwwroot folder
👍 That's what to do.
If the user changes their base URL, they reason they will do that is because they are hosting the entire site on some non-root path. And in that case, the wwwroot still corresponds to the base URL.
Example: for a site hosted at http://domain/mydir/, the base URI would be /mydir/, so the file in wwwroot/a/b/c.gif would be reachable at the URL http://domain/mydir/a/b/c/gif, which as a base-relative URL is still a/b/c.gif. So in summary you can ignore what the base URI actually is.
If a user creates a more nonstandard setup where the base URI doesn't match the site's content root, they will have other problems to solve too and the tooling isn't expected to know about that.