buildPathname(object)
- Core
- Optional
- Tooling
Description
Turns a path template and a parameters object into a string of form /path/user?a=1&b=2
var pathname = m.buildPathname("/path/:id", {id: "user", a: "1", b: "2"})
// "/path/user?a=1&b=2"
Signature
pathname = m.buildPathname(object)
Argument | Type | Required | Description |
---|---|---|---|
path |
String |
Yes | A URL path |
query |
Object |
Yes | A key-value map to be converted into a string |
returns | String |
A string representing the URL with the query string |
How it works
The m.buildPathname
creates a path name from a path template and a parameters object. It's useful for building URLs, and it's what m.route
and m.request
use internally to interpolate paths. It uses m.buildQueryString
to generate the query parameters to append to the path name.
var pathname = m.buildPathname("/path/:id", {id: "user", a: 1, b: 2})
// pathname is "/path/user?a=1&b=2"