107 lines
4.2 KiB
HTML
107 lines
4.2 KiB
HTML
<html>
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<title> parsePathname(string) - Mithril.js</title>
|
|
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" />
|
|
<link href="style.css" rel="stylesheet" />
|
|
<link rel="icon" type="image/png" sizes="32x32" href="favicon.png" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
</head>
|
|
<body>
|
|
<header>
|
|
<section>
|
|
<a class="hamburger" href="javascript:;">≡</a>
|
|
<h1><img src="logo.svg"> Mithril <small>2.0.0-rc.5</small></h1>
|
|
<nav>
|
|
<a href="index.html">Guide</a>
|
|
<a href="api.html">API</a>
|
|
<a href="https://gitter.im/MithrilJS/mithril.js">Chat</a>
|
|
<a href="https://github.com/MithrilJS/mithril.js">GitHub</a>
|
|
</nav>
|
|
</section>
|
|
</header>
|
|
<main>
|
|
<section>
|
|
<h1 id="parsepathnamestring"><a href="#parsepathnamestring">parsePathname(string)</a></h1>
|
|
<ul>
|
|
<li>Core<ul>
|
|
<li><a href="hyperscript.html">m</a></li>
|
|
<li><a href="render.html">m.render</a></li>
|
|
<li><a href="mount.html">m.mount</a></li>
|
|
<li><a href="route.html">m.route</a></li>
|
|
<li><a href="request.html">m.request</a></li>
|
|
<li><a href="jsonp.html">m.jsonp</a></li>
|
|
<li><a href="parseQueryString.html">m.parseQueryString</a></li>
|
|
<li><a href="buildQueryString.html">m.buildQueryString</a></li>
|
|
<li><a href="trust.html">m.trust</a></li>
|
|
<li><a href="fragment.html">m.fragment</a></li>
|
|
<li><a href="redraw.html">m.redraw</a></li>
|
|
<li><a href="version.html">m.version</a></li>
|
|
<li><a href="promise.html">Promise</a></li>
|
|
</ul>
|
|
</li>
|
|
<li>Optional<ul>
|
|
<li><a href="stream.html">Stream</a></li>
|
|
</ul>
|
|
</li>
|
|
<li>Tooling<ul>
|
|
<li><a href="https://github.com/MithrilJS/mithril.js/blob/master/ospec">Ospec</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<hr>
|
|
<h3 id="description"><a href="#description">Description</a></h3>
|
|
<p>Turns a string of the form <code>/path/user?a=1&b=2</code> to an object</p>
|
|
<pre><code class="language-javascript">var object = m.parsePathname("/path/user?a=1&b=2")
|
|
// {path: "/path/user", params: {a: "1", b: "2"}}</code></pre>
|
|
<hr>
|
|
<h3 id="signature"><a href="#signature">Signature</a></h3>
|
|
<p><code>object = m.parsePathname(string)</code></p>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Argument</th>
|
|
<th>Type</th>
|
|
<th>Required</th>
|
|
<th>Description</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr>
|
|
<td><code>string</code></td>
|
|
<td><code>String</code></td>
|
|
<td>Yes</td>
|
|
<td>A URL</td>
|
|
</tr>
|
|
<tr>
|
|
<td><strong>returns</strong></td>
|
|
<td><code>Object</code></td>
|
|
<td></td>
|
|
<td>A <code>{path, params}</code> pair where <code>path</code> is the <a href="paths.html#path-normalization">normalized path</a> and <code>params</code> is the <a href="paths.html#parameter-normalization">parsed parameters</a>.</td>
|
|
</tr>
|
|
</tbody></table>
|
|
<p><a href="signatures.html">How to read signatures</a></p>
|
|
<hr>
|
|
<h3 id="how-it-works"><a href="#how-it-works">How it works</a></h3>
|
|
<p>The <code>m.parsePathname</code> 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 <a href="route.html"><code>m.route</code></a> uses internally to normalize paths to later match them. It uses <a href="parseQueryString.html"><code>m.parseQueryString</code></a> to parse the query parameters into an object.</p>
|
|
<pre><code class="language-javascript">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"}</code></pre>
|
|
|
|
<hr />
|
|
<small>License: MIT. © Leo Horie.</small>
|
|
</section>
|
|
</main>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.6.0/prism.min.js" defer></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.6.0/components/prism-jsx.min.js" defer></script>
|
|
<script src="https://unpkg.com/mithril@2.0.0-rc.5/mithril.js" async></script>
|
|
<script>
|
|
document.querySelector(".hamburger").onclick = function() {
|
|
document.body.className = document.body.className === "navigating" ? "" : "navigating"
|
|
document.querySelector("h1 + ul").onclick = function() {
|
|
document.body.className = ''
|
|
}
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|