Home > Web Front-end > JS Tutorial > Instructions for using the url.resolve method in node.js_node.js

Instructions for using the url.resolve method in node.js_node.js

WBOY
Release: 2016-05-16 16:27:50
Original
1743 people have browsed it

Method description:

Insert or replace the original tag for URL or href. (If you don’t understand, you can look at examples)

Grammar:

Copy code The code is as follows:

url.resolve(from, to)

Since this method belongs to the url module, the url module needs to be introduced before use (var url= require(“url”) )

Receive parameters:

from Source address

to tags that need to be added or replaced

Example:

Copy code The code 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:

Copy code The code is as follows:

Url.prototype.resolve = function(relative) {
return this.resolveObject(urlParse(relative, false, true)).format();
};
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template