-
-
Notifications
You must be signed in to change notification settings - Fork 428
Update <base> to reflect current route? #228
Comments
I would far prefer As for referencing assets etc. why not do what we've always done and use a path relative to the site root: <link rel=stylesheet href=/global.css> Is there something with the routing that requires |
In my experience |
It's all to do with basepath. It's not uncommon to need to mount an app to a path other than root, and this was the easiest way I could find to make that possible. It is a nuisance though (for example, the other day I found that Safari and Firefox trip over |
Why not substitute links during parsing to make it absolute? Eg
It won't solve fetch issue of course, I don't know if someone uses relative urls there. Maybe pass |
Any updates on this? |
I would solve it with #984, perhaps someone can review? |
Also solved by #1152. A workaround while waiting for a solution in sapper is monkey-patching res.end: // add this middleware before sapper.middleware
function removeBaseTag(req, res, next) {
const resEnd = res.end;
res.end = function () {
const body = arguments[0];
if (typeof body === "string") {
arguments[0] = body.replace(/<base[^>]+>/, '');
}
resEnd.call(this, ...arguments);
}
next();
} |
Interesting approach, but that would break routes with a slash in it because styles are loaded from |
Not sure if you mean this particular example or the pull request, but both could make links starting with If it is not clear, you would use the This is the naive approach, and might have corner cases I have not thought out, but I believe
A |
Made a patch to save y'all trouble – based on @thgh's changes and can be installed with patch-package, like @arve0 suggested. Thank you guys! |
Are there any thoughts from people pushing for this (or the various related issues/PRs) about what hrefs should be relative to? Sapper currently allows page routes to be accessed with or without a trailing slash, which complicates the idea of relative links, and makes the whole thing messier. Even if we decided to normalize the URLs in some way (at least for the purpose of |
@Conduitry How about |
I won't call having two urls pointing to the same page a perfect solution either. The classic way is having a setting for normalization behaviour on application level. The approach suggested by @nolanlawson is more flexible, but in most cases I'd prefer the normalization to be uniform within an app. Why can't we have all the options as an
|
I'd be happy with this as a fix to #519. It's not about redirecting requests, that is the role of the web-server, it's about writing link hrefs to be going to the correct url in the first place |
I'd just like to add my ¢2: Having relative URL's will also greatly help with an internationalized site. e.g. on a link like Which is also a problem because for the purpose of DRY programming Of course, the site developer will then need to make sure that path's are used correctly. |
At present,
<base>
is the same for all pages, which means you can't use relative URLs. This was introduced for good reasons, but it turns out to cause problems.I'm not sure that it can be removed without breaking base URL functionality though — for example, things like this would break:
Also,
this.fetch(relativeUrl, ..)
is tricky, because it needs to be relative to the page you're going to, not the page you're currently on, so it can't just straightforwardly delegate tofetch
as it currently does.It might be that the solution is just to not use relative URLs 😬 Unless there's already a creative solution for this problem?
The text was updated successfully, but these errors were encountered: