-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #281 from vaadin/feature/45
feat(router): add urlForPath static method to generate URLs
- Loading branch information
Showing
10 changed files
with
405 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.