Skip to content
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

How to get an unqualified url? #78

Open
ccorcos opened this issue Oct 31, 2017 · 3 comments
Open

How to get an unqualified url? #78

ccorcos opened this issue Oct 31, 2017 · 3 comments

Comments

@ccorcos
Copy link

ccorcos commented Oct 31, 2017

If I have a url like https://www.example.com/abc?q=10#hello then I can use parsed.href.slice(parsed.origin.length) to get just /abc?q=10#hello. However, this doesnt work if I create parsed using the unqualified url because origin will be "null".

I see another discussion going on about "null" but regardless, I think it would be nice if there was a convenient way of getting an unqualified url using this library.

@lpinca
Copy link
Member

lpinca commented Nov 1, 2017

I'm not sure I understand. If you use a relative URL, isn't the whole URL what you are looking for?

let url;
if (parsed.origin === 'null') {
  url = parsed.href;
} else {
  url = parsed.href.slice(parsed.origin.length);
}

@ccorcos
Copy link
Author

ccorcos commented Nov 1, 2017

Yes. But it's prone to error if I have to put that if statement everything. People who are unfamiliar with this library will see === 'null' and thing wtf?

@lpinca
Copy link
Member

lpinca commented Nov 1, 2017

You can use a baseUrl in that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants