File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -1300,6 +1300,24 @@ url.resolve('http://example.com/', '/one'); // 'http://example.com/one'
13001300url .resolve (' http://example.com/one' , ' /two' ); // 'http://example.com/two'
13011301```
13021302
1303+ You can achieve the same result using the WHATWG URL API:
1304+
1305+ ``` js
1306+ function resolve (from , to ) {
1307+ const resolvedUrl = new URL (to, new URL (from, ' resolve://' ));
1308+ if (resolvedUrl .protocol === ' resolve:' ) {
1309+ // `from` is a relative URL.
1310+ const { pathname , search , hash } = resolvedUrl;
1311+ return pathname + search + hash;
1312+ }
1313+ return resolvedUrl .toString ();
1314+ }
1315+
1316+ resolve (' /one/two/three' , ' four' ); // '/one/two/four'
1317+ resolve (' http://example.com/' , ' /one' ); // 'http://example.com/one'
1318+ resolve (' http://example.com/one' , ' /two' ); // 'http://example.com/two'
1319+ ```
1320+
13031321<a id =" whatwg-percent-encoding " ></a >
13041322## Percent-encoding in URLs
13051323
You can’t perform that action at this time.
0 commit comments