-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle relative URLs #138
Handle relative URLs #138
Conversation
Hi @ashsearle - it might be possibly to dramatically simplify this by just changing |
Hi, that'd work for |
@ashsearle Good point. That said, what about using let a = typeof document!=='undefined' && document.createElement('a');
function makeAbsolute(url) {
if (a) {
a.setAttribute('href', url);
url = a.href;
}
return url;
} |
@@ -25,27 +25,61 @@ function setUrl(url, type='push') { | |||
} | |||
|
|||
|
|||
function getCurrentLocation() { | |||
return (customHistory && customHistory.location) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation is good, but if it's only ever called from getCurrentUrl()
, let's just inline it there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's also called from the new resolve
method used by route
.
I was wondering whether to tweak resolve
to take a base
parameter as well, then move it to util.js
and add test-cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depends - there was talk about moving customHistory
to be a property of Router
instances so that they had proper instance separation instead of the singleton stuff. Might be better to go that route rather than making it more singelton-ey? Different PR I guess though.
Any thoughts on the link parsing stuff? Seems like a size tradeoff, but the benefit of your custom parser is that it works under Node where |
A few thoughts:
If you're not worried about node support then going the Is there a minimum version of node you support? I'm wondering if it'd make most sense to check for the URL API first (also in node), then fallback to |
SSR is always single-pass, yeah. Anything else would require a |
I've switched code over to use ... unfortunately I think I may have screwed the pooch with poor git management. Perhaps I should start again with a clean master? |
Nah, I'm not a pedant about git, doesn't matter to me at all. -edit- I think I get what you mean - fine by me if you want a clean one. |
} | ||
} | ||
return didRoute; | ||
return ROUTERS.reduce((didRoute, router) => (router.routeTo(url) === true || didRoute), false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm - did these get added from another PR? I don't remember them being here before. .some()
and .reduce()
aren't supported in some of the browsers we support, and add to the overall size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know, I often forget these things now haha. Still curious about the filesize hit for all those function definitions, but I guess this repo isn't exactly aiming for extreme small size.
I'll pull this down this weekend and play around with it - I feel horrible about how long this PR and the nested routers PR have been sitting here, really want to get things merged since you guys did so much work on them!
Tried to resolve conflicts with #169, hopefully I didn't mess anything up. |
Had a thought as I was resolving: there are kinda two cases here, and it might be a worthy exercise to think of them as different. The first case is being able to invoke The second case, and in my head I'm thinking this is the more common one, is that there is an anchor tag in a document that itself is bound to a URL, and we'd like to use its resolved Interestingly, in splitting these two up, I've realize that the second case is actually something we can get for less than free (saves a few bytes) by simply switching from So then I wonder, maybe since this lib is fairly narrowly aimed at being minimal, we should take more time pondering the first case (the harder one, requiring the lovely parsing setup you've defined in this PR), and just jump on the second (freebie) case since it's an easy win. Thoughts? |
…s for links in a document (not `route('./foo')`). See #138.
…s for links in a document (not `route("./foo")`). See #138.
@developit Should rely on browser built-ins as much as possible. They're actually pretty good. We can get both points taken care of by just utilizing // starting at: http://example.com/blog
route('foo') //=> http://example.com/blog/foo
route('/foo') //=> http://example.com/foo
<a href="foo">foo</a> //=> http://example.com/blog/foo
<a href="/foo">foo</a> //=> http://example.com/foo Doing it this way works with/without JS enabled. It also works regardless of what |
Right right - my point was that with |
Reimplemented in #243 |
Fixes #129, enabling router to intercept
a
tags with relative URLs, as well as enablingroute()
to handle relative URLsAn alternative to the
resolve
function implemented would be to resolve URLs using something like:...the problem I had with that was putting appropriate guards in place to make it work in a pure node environment.