url-params is a polymer element which is the best way to read params directly from url. If you employ app-route or app-location these are two way binded elements and soon as value changes it gets mutated to url, which effects in the desired performance of web app.
url-params is specifically build for multi page app approach, because in single page app everything is passed to inner page via parent routes.
npm install @elifent/url-params
<html>
<head>
<script type="module">
import '@elifent/url-params/url-params.js';
</script>
</head>
<body>
<url-params
pattern="/path/to/page/:data/:to/:parse"
data="{{params}}"
></url-params>
Value in data is {{params.data}} <br>
Value in to is {{params.to}} <br>
Value in parse is {{params.parse}} <br>
</body>
</html>
import {PolymerElement, html} from '@polymer/polymer';
import '@elifent/url-params/url-params.js';
class SampleElement extends PolymerElement {
static get template() {
return html`
<url-params
pattern="/path/to/page/:data/:to/:parse"
data="{{params}}"
></url-params>
Value in data is {{params.data}} <br>
Value in to is {{params.to}} <br>
Value in parse is {{params.parse}} <br>
`;
}
}
customElements.define('sample-element', SampleElement);
Alternatively you can read all params from a GET request. To do it use pattern as ?
import {PolymerElement, html} from '@polymer/polymer';
import '@elifent/url-params/url-params.js';
class SampleElement extends PolymerElement {
static get template() {
return html`
<url-params
pattern="?"
data="{{params}}"
></url-params>
Value in data is {{params.data}} <br>
Value in to is {{params.to}} <br>
Value in parse is {{params.parse}} <br>
`;
}
}
customElements.define('sample-element', SampleElement);
In this case if your url is path/to/page?data=a&to=b&parse=c then you will be able to get params.data as a.
Running demo locally
git clone https://github.com/elifent/url-params
cd url-params
npm install
npm install -g polymer-cli
polymer serve --npm
open http://127.0.0.1:<port>/demo/index.html?name=George&age=30&sex=male
Found issues? Let me know