How to use a query string at Polymer 1.0

1.1k Views Asked by At

Im using a latest version Polymer Starter Kit, and use page.js as a router.

I want my url like this : http://host.com/search?keywords=blablabla

But i can not access a query string, im also search at github project of page.js: https://github.com/visionmedia/page.js/ and viewing a sample of query string but i dont understand to implement it to my project

Here my snippets of my code :

page('/search', function(data) {
  app.route = 'search';
  app.params = data.queryParams;
});
1

There are 1 best solutions below

0
On

I use query strings with page.js in a project that is derived from the Polymer Starter Kit. They work fine.

Try this:

page('/search', function(data) {
  app.route = 'search';
  app.params = data.querystring;
});

The "route" and "params" names are now available for binding in the "app" context. In the Starter Kit the "app" context is used in the top level template defined in index.html.

If you follow the Starter Kit's example your routes will use the hashing pattern and will appear as follows:

 http://host.com/#!/search?keywords=blablabla  

In this case app.route is equal to "search" and app.params is equals to "keywords=blababla". Of course, you will have to decode the query string on your own.