Use instructions for the url.resolve method in node.js
- 2020-03-30 04:36:16
- OfStack
Method description:
Insert or replace the original tag for the URL or href. (you can read the examples if you don't understand)
Grammar:
url.resolve(from, to)
Since this method belongs to the url module, the url module (var url= require(" url ")) needs to be introduced before use.
Receiving parameters:
From Source address
To Tags that need to be added or replaced
Example:
var url = require('url');
var a = url.resolve('/one/two/three', 'four') ,
b = url.resolve('http://example.com/', '/one'),
c = url.resolve('http://example.com/one', '/two');
console.log(a +","+ b +","+ c);
//Output:
///one/two/four
//http://example.com/one
//http://example.com/two
Source:
Url.prototype.resolve = function(relative) {
return this.resolveObject(urlParse(relative, false, true)).format();
};