Skip to content

Commit

Permalink
Merge pull request #281 from vaadin/feature/45
Browse files Browse the repository at this point in the history
feat(router): add urlForPath static method to generate URLs
  • Loading branch information
platosha authored Oct 18, 2018
2 parents 5a2c378 + 89f2604 commit 07e6f43
Show file tree
Hide file tree
Showing 10 changed files with 405 additions and 58 deletions.
87 changes: 59 additions & 28 deletions analysis.json
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@
"column": 2
},
"end": {
"line": 1659,
"line": 1662,
"column": 3
}
},
Expand All @@ -664,11 +664,11 @@
"privacy": "private",
"sourceRange": {
"start": {
"line": 1661,
"line": 1664,
"column": 2
},
"end": {
"line": 1665,
"line": 1668,
"column": 3
}
},
Expand All @@ -689,11 +689,11 @@
"privacy": "private",
"sourceRange": {
"start": {
"line": 1667,
"line": 1670,
"column": 2
},
"end": {
"line": 1673,
"line": 1676,
"column": 3
}
},
Expand All @@ -716,11 +716,11 @@
"privacy": "private",
"sourceRange": {
"start": {
"line": 1675,
"line": 1678,
"column": 2
},
"end": {
"line": 1718,
"line": 1721,
"column": 3
}
},
Expand All @@ -743,11 +743,11 @@
"privacy": "private",
"sourceRange": {
"start": {
"line": 1720,
"line": 1723,
"column": 2
},
"end": {
"line": 1726,
"line": 1729,
"column": 3
}
},
Expand All @@ -763,11 +763,11 @@
"privacy": "private",
"sourceRange": {
"start": {
"line": 1728,
"line": 1731,
"column": 2
},
"end": {
"line": 1734,
"line": 1737,
"column": 3
}
},
Expand All @@ -783,11 +783,11 @@
"privacy": "private",
"sourceRange": {
"start": {
"line": 1736,
"line": 1739,
"column": 2
},
"end": {
"line": 1757,
"line": 1760,
"column": 3
}
},
Expand All @@ -810,11 +810,11 @@
"privacy": "private",
"sourceRange": {
"start": {
"line": 1759,
"line": 1762,
"column": 2
},
"end": {
"line": 1769,
"line": 1772,
"column": 3
}
},
Expand All @@ -834,11 +834,11 @@
"privacy": "private",
"sourceRange": {
"start": {
"line": 1771,
"line": 1774,
"column": 2
},
"end": {
"line": 1793,
"line": 1796,
"column": 3
}
},
Expand All @@ -855,11 +855,11 @@
"privacy": "public",
"sourceRange": {
"start": {
"line": 1801,
"line": 1804,
"column": 2
},
"end": {
"line": 1803,
"line": 1806,
"column": 3
}
},
Expand All @@ -875,11 +875,11 @@
"privacy": "public",
"sourceRange": {
"start": {
"line": 1809,
"line": 1812,
"column": 2
},
"end": {
"line": 1811,
"line": 1814,
"column": 3
}
},
Expand All @@ -895,11 +895,11 @@
"privacy": "private",
"sourceRange": {
"start": {
"line": 1813,
"line": 1816,
"column": 2
},
"end": {
"line": 1816,
"line": 1819,
"column": 3
}
},
Expand All @@ -921,11 +921,11 @@
"privacy": "public",
"sourceRange": {
"start": {
"line": 1834,
"line": 1837,
"column": 2
},
"end": {
"line": 1836,
"line": 1839,
"column": 3
}
},
Expand All @@ -941,17 +941,48 @@
"type": "void"
}
},
{
"name": "urlForPath",
"description": "Generates a URL for the given route path, optionally performing\nsubscription of parameters.",
"privacy": "public",
"sourceRange": {
"start": {
"line": 1852,
"column": 2
},
"end": {
"line": 1854,
"column": 3
}
},
"metadata": {},
"params": [
{
"name": "path",
"type": "!string",
"description": "string route path declared in [express.js syntax](https://expressjs.com/en/guide/routing.html#route-paths\")."
},
{
"name": "parameters",
"type": "?Object",
"description": "Optional object with route path parameters,\nwhere keys are route parameter names or indicies, and values\nare parameter values."
}
],
"return": {
"type": "string"
}
},
{
"name": "go",
"description": "Triggers navigation to a new path and returns without waiting until the\nnavigation is complete.",
"privacy": "public",
"sourceRange": {
"start": {
"line": 1844,
"line": 1862,
"column": 2
},
"end": {
"line": 1846,
"line": 1864,
"column": 3
}
},
Expand Down Expand Up @@ -985,7 +1016,7 @@
"column": 0
},
"end": {
"line": 1847,
"line": 1865,
"column": 1
}
},
Expand Down
10 changes: 10 additions & 0 deletions demo/demos.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
"image": ""
}
},
{
"name": "URL Generation",
"url": "vaadin-router-url-generation-demos",
"src": "vaadin-router-url-generation-demos.html",
"meta": {
"title": "Vaadin Router URL Generation Examples",
"description": "",
"image": ""
}
},
{
"name": "Redirects",
"url": "vaadin-router-redirect-demos",
Expand Down
77 changes: 77 additions & 0 deletions demo/vaadin-router-url-generation-demos.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<dom-module id="vaadin-router-url-generation-demos">
<template>
<style include="vaadin-component-demo-shared-styles">
:host {
display: block;
}
</style>

<h3>The <code>Router.urlForPath</code> method</h3>
<p>
<b><code>
<a target="_parent"
href="..#/classes/Vaadin.Router#staticmethod-urlForPath">
Router.urlForPath(path, parameters)</a>
</code></b> is a static helper method, that generates a URL for
the given route path, optionally performing substitution of parameters.
</p>
<p>
Arguments:
</p>
<ul>
<li><code>path</code> — a string route path defined in express.js syntax</li>
<li><code>parameters</code> — optional object with parameters for
path substitution</li>
</ul>
<vaadin-demo-snippet id="vaadin-router-url-generation-demo-1" iframe-src="iframe.html">
<template preserve-content>
<div id="outlet"></div>
<dom-module id="x-main-layout">
<template>
<a href$="[[_getUrlForHome()]]">Home</a>
<a href$="[[_getUrlForUserList()]]">Users</a>
<a href$="[[_getUrlForUser('me')]]">My profile</a>
<slot></slot>
</template>
</dom-module>
<script>
// import {Router} from '@vaadin/router'; // for Webpack / Polymer CLI
// const Router = Vaadin.Router; // for vaadin-router.umd.js
const router = new Router(document.getElementById('outlet'));
router.setRoutes([
{path: '/', component: 'x-main-layout', children: [
{path: '/', component: 'x-home-view'},
{path: '/users', component: 'x-user-list'},
{path: '/users/:user', component: 'x-user-profile'},
]}
]);

Polymer({
is: 'x-main-layout',

_getUrlForPath() {
return Router.urlForPath('/');
},

_getUrlForUserList() {
return Router.urlForPath('/users');
},

_getUrlForUser(user) {
return Router.urlForPath('/users/:user', {user: user});
}
});

</script>
</template>
</vaadin-demo-snippet>
</template>
<script>
class VaadinRouterLinkGenerationDemos extends DemoReadyEventEmitter(ElementDemo(Polymer.Element)) {
static get is() {
return 'vaadin-router-url-generation-demos';
}
}
customElements.define(VaadinRouterLinkGenerationDemos.is, VaadinRouterLinkGenerationDemos);
</script>
</dom-module>
Loading

0 comments on commit 07e6f43

Please sign in to comment.