Thursday, 15 January 2015

Pass a URL into a Dart app -


I have a page with links, all of these links end in the same way, for example www.site.com / Fruit / apples, www.site.com/fruit/bananas, www.site.com/fruit/oranges , etc. I want to call all these links to the DART app and the app has to do some processing and then redirect you to wherever you need to go (orange page vs banana page). In this way, to avoid having a real HTML file for every single fruit, I can instead use a landing template which is populated with variable fruit data.

The part I have been hanging on is passing the URL to the dart app so that it can handle. I understand that main () can not get the argument, then what is another way?

You can use the URL to handle for yourself.

For example:

  import 'package: route / client.dart'; Final fruit url = new urlpattern (r / ft / (\ w +) '); Main () {var router = new router () ..addHandler (fruit url, show fret) .. list (); } ZERO SHOW FREET (string path) {var fruit = FULL URL.PRS (re ..path) [0]; // Display the page according to the type of fruit}   

If you do not need to control the actual routes, and you want to handle any query parameters passed from the form Are you You do not have to use the route package and you can parse the URL instead:

  map params = {}; // If the arguments had been given, decode them into Parameters map if (window.location.search.length> 1) {// break all logic in the form: fruit = list of apple & lt; String & gt; QueryPairs = window.location.search.substring (1) .split ('& amp;'); (For the query pair in the query query pair) {// Add the argument in Parameters map: key = fruit, value = apple list & lt; String & gt; QueryPairList = queryPair.split ('='); Consultation [queryPairList [0]] = query pyelist [1]; }} // Handle the proper action based on the switch of fruit (param [[fruit ']) {case' apple ': // break; // ... case 'orange': // ... break; }    

No comments:

Post a Comment