erikringsmuth / app-router

Router for Web Components
https://erikringsmuth.github.io/app-router/
MIT License
610 stars 83 forks source link

Please consider making URL components visible to consumers #145

Closed chisholmd closed 8 years ago

chisholmd commented 8 years ago

Eg.<app-router id='mainroutes'>

app.$.mainroutes.path app.$.mainroutes.hash app.$.mainroutes.query

However granular you parse the URL could you just expose all those?

jmalonzo commented 8 years ago

hmm.. how is this different from window.location.x?

chisholmd commented 8 years ago

I assume you mean how is this different from "window.location.href".

Anytime I am doing something that has already been done I feel like I am wasting resources and hurting performance. I have found that bad performance is often death by a thousand cuts, so every little bit counts. So you are correct, I could do a window.location.href and parse it myself into its constituent parts, but app.router has already parsed it so I am duplicating effort hence the waste.

The question is "Is there a performance cost to app.router making those values public?". If not then why not do it?

It could also be useful in debugging. Eg. "Why isn't my route working? I wish I could see how app.router is parsing the URL?"

So you are absolutely right that it is easy to do window.location.href but its also easy to expose those values that have already been parsed and would provide transparency into the component. I plan on doing it in my local version.

It was a suggestion here.

jmalonzo commented 8 years ago

I mean you could use window.location.hash, window.location.query, window.location.pathname, etc... No need to parse it as the browser already does this for you for free, irrespective of whether you're using app-router or another routing library.

https://developer.mozilla.org/en-US/docs/Web/API/Location

chisholmd commented 8 years ago

Well heck :) Thanks for that. No I did not know those were already available.