方法說明:
為URL或 href 插入 或 替換原有的標籤。 (不懂可以看範例)
文法:
url.resolve(from, to)
由於方法屬於url模組,使用前需要引入url模組(var url= require(“url”) )
接收參數:
from 來源位址
to 且需新增或取代的標籤
範例:
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);
//輸出結果:
///one/two/four
//http://example.com/one
//http://example.com/two
原始碼:
Url.prototype.resolve = function(relative) {
return this.resolveObject(urlParse(relative, false, true)).format();
};