Today I Learned

hashrocket A Hashrocket project

Build URLs with Window Location

Want to build URLs with JavaScript? Try thewindow.location object.

This came from a React.js project we're working on. It uses ES6 template string interpolation, which isn't necessary but definitely is nice:

`${window.location.protocol}//${window.location.host}/posts/${this.props.postID}/edit`

Which becomes:

"https://secret-project.com/posts/42/edit"
See More #javascript TILs
Looking for help? At Hashrocket, our JavaScript experts launch scalable, performant apps on the Web, Android and iOS. Contact us and find out how we can help you.