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;
});
  • Couldn't this acomplish your objective?[Stack Answer](http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript) – Alejandro Vales Feb 09 '16 at 10:09
  • Related: https://stackoverflow.com/questions/40668826/how-to-get-query-string-in-polymer – dskrvk Apr 04 '17 at 21:09

1 Answers1

0

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.

jptknta
  • 787
  • 6
  • 15