Method description:
Insert or replace the original tag for the URL or href. (If you don’t understand, please see the example)
grammar:
The code copy is as follows:
url.resolve(from, to)
Since this method belongs to the url module, you need to introduce the url module before use (var url= require("url") )
Receive parameters:
from source address
to tags that need to be added or replaced
example:
The code copy is as follows:
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 result:
///one/two/four
//http://example.com/one
//http://example.com/two
Source code:
The code copy is as follows:
Url.prototype.resolve = function(relative) {
return this.resolveObject(urlParse(relative, false, true)).format();
};