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

buildPathname(object) ​

Description ​

Turns a path template and a parameters object into a string of form /path/user?a=1&b=2

javascript
var pathname = m.buildPathname('/path/:id', { id: 'user', a: '1', b: '2' });
// "/path/user?a=1&b=2"

Signature ​

pathname = m.buildPathname(path, query)

ArgumentTypeRequiredDescription
pathStringYesA URL path
query ObjectYesA key-value map to be converted into a string
returnsStringA string representing the URL with the query string

How to read signatures

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.

javascript
var pathname = m.buildPathname('/path/:id', { id: 'user', a: 1, b: 2 });

// pathname is "/path/user?a=1&b=2"
Pager
Previous pagem.buildQueryString
Next pagem.parsePathname

Released under the MIT License.

Copyright (c) 2024 Mithril Contributors

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

Released under the MIT License.

Copyright (c) 2024 Mithril Contributors