Rizky Nugraha February 2016

How to use a query string at Polymer 1.0

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;
});

Answers


jptknta February 2016

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.

Post Status

Asked in February 2016
Viewed 1,936 times
Voted 11
Answered 1 times

Search




Leave an answer