Skip to content
Mithril.js 2
Main Navigation GuideAPI

English

简体中文
繁體中文
Español
Français
Русский
Português – Brasil
Deutsch
日本語
한국어
Italiano
Polski
Türkçe
čeština
magyar

English

简体中文
繁體中文
Español
Français
Русский
Português – Brasil
Deutsch
日本語
한국어
Italiano
Polski
Türkçe
čeština
magyar

Appearance

Sidebar Navigation

API

Core API

m

m.render

m.mount

m.route

m.request

m.parseQueryString

m.buildQueryString

m.buildPathname

m.parsePathname

m.trust

m.fragment

m.redraw

m.censor

Optional API

Stream

Guide

On this page

parsePathname(string) ​

Description ​

Turns a string of the form /path/user?a=1&b=2 to an object

javascript
var object = m.parsePathname('/path/user?a=1&b=2');
// {path: "/path/user", params: {a: "1", b: "2"}}

Signature ​

object = m.parsePathname(url)

ArgumentTypeRequiredDescription
urlStringYesA URL
returnsObjectA {path, params} pair where path is the normalized path and params is the parsed parameters.

How to read signatures

How it works ​

The m.parsePathname method creates an object from a path with a possible query string. It is useful for parsing a local path name into its parts, 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.

javascript
var data = m.parsePathname('/path/user?a=hello&b=world');

// data.path is "/path/user"
// data.params is {a: "hello", b: "world"}

General-purpose URL parsing ​

The method is called parsePathname because it applies to pathnames. If you want a general-purpose URL parser, you should use the global URL class instead.

Pager
Previous pagem.buildPathname
Next pagem.trust

Released under the MIT License.

Copyright (c) 2024 Mithril Contributors

https://mithril.js.org/parsePathname.html

Released under the MIT License.

Copyright (c) 2024 Mithril Contributors