parsePathname(string)
- Core
- Optional
- Tooling
Description
Turns a string of the form /path/user?a=1&b=2
to an object
var object = m.parsePathname("/path/user?a=1&b=2")
// {path: "/path/user", params: {a: "1", b: "2"}}
Signature
object = m.parsePathname(string)
Argument | Type | Required | Description |
---|---|---|---|
string |
String |
Yes | A URL |
returns | Object |
A {path, params} pair where path is the normalized path and params is the parsed parameters. |
How it works
The m.parsePathname
method creates an object from a path with a possible query string and hash string. It is useful for parsing a URL into more sensible paths, and it's what m.route
uses internally to normalize paths to later match them. It uses m.parseQueryString
to parse the query parameters into an object.
var data = m.parsePathname("/path/user?a=hello&b=world#random=hash&some=value")
// data.path is "/path/user"
// data.params is {a: "hello", b: "world", random: "hash", some: "value"}
License: MIT. © Leo Horie.