Kolyunya
Kolyunya

Reputation: 6240

Prevent addition of a trailing slash to a URL

I'm using the URL API in my React Native application to conveniently construct query strings for my requests.

I found out that this API adds a trailing slash to the URL which breaks all the requests.

let uri = new URL('https://example.com/path');
console.log(uri.toString()); 
// https://example.com/path/

I made some tests in a browser (Chromium 87) and found out that this behavior is not present there. Is it a quirk of React or React Native?

The question is how can I prevent the addition of a trailing space to the URL?

Upvotes: 0

Views: 766

Answers (1)

vineeth pappu
vineeth pappu

Reputation: 542

Try using

uri.href

instead of uri.toString()

Upvotes: 0

Related Questions