सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
एक डार्ट पैकेज जो मार्ग पैटर्न जैसे '/user/:id' को रूट मैचिंग के लिए नियमित व्यंजक में बदलता है। यह पैरामीटर कैप्चर, वाइल्डकार्ड और वैकल्पिक सेगमेंट को समर्थन देकर डायनामिक पथ विश्लेषण को संभव बनाता है। फ्लटर ऐप में रूटिंग सिस्टम बनाने के लिए आदर्श है, यह निर्धारित रूट्स के खिलाफ URL को मैच करने के लिए हल्का समाधान प्रदान करता है। पैकेज सभी प्रमुख प्लेटफॉर्मों के साथ संगत है और मौजूदा नेविगेशन तर्क के साथ बिना किसी दिक्कत के एकीकृत होता है।
उपयोग
डायनामिक रूट मैचिंग
URL पैटर्न विश्लेषण
नेविगेशन सिस्टम कार्यान्वयन
मार्ग पैरामीटर निकालना
कस्टम रूटर विकास
API एंडपॉइंट मैचिंग
मुख्य विशेषताएँ
नामित पैरामीटर का समर्थन करता है (उदाहरण: :id)
वैकल्पिक खंडों का निर्वहन करता है
वाइल्डकार्ड मैचिंग शामिल है
पुनर्उपयोगी RegExp ऑब्जेक्ट उत्पन्न करता है
हल्का और तेज़
क्रॉस-प्लेटफॉर्म संगतता
इनके लिए उपयुक्त
कस्टम रूटर बनाने वाले डेवलपर्स
लचीले URL मार्गदर्शन की आवश्यकता वाले ऐप्स
गतिशील पथ के साथ फ्रंटएंड नेविगेशन
जटिल रूट पैटर्न का विश्लेषण
मौजूदा रूटिंग लाइब्रेरी के साथ एकीकरण
विचार योग्य बातें
प्रश्न पैरामीटर को संभालता नहीं है
कोई निर्मित मध्यस्थ समर्थन नहीं है
हाथ से रूट समाधान की आवश्यकता है
मार्ग स्तर के मिलान तक सीमित
पूर्ण HTTP सर्वर उपयोग के लिए डिज़ाइन नहीं किया गया है
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
path_to_regexp
Converts a path such as /user/:id into a regular expression.
Matching
pathToRegExp() converts a path specification into a regular expression that
matches conforming paths.
By default, parameters match anything until the next delimiter. This behavior
can be customized by specifying a regular expression in parentheses following
a parameter name.
Parameters can be extracted from a path specification during conversion into a
regular expression.
final parameters = <String>[];
final regExp = pathToRegExp('/user/:id', parameters: parameters);
parameters; // => ['id']
Extracting Arguments
extract() maps the parameters of a path specification to their corresponding
arguments in a match.
final parameters = <String>[];
final regExp = pathToRegExp('/user/:id', parameters: parameters);
final match = regExp.matchAsPrefix('/user/12');
extract(parameters, match); // => {'id': '12'}
Generating
pathToFunction() converts a path specification into a function that generates
matching paths.
final toPath = pathToFunction('/user/:id');
toPath({'id': '12'}); // => '/user/12'
Tokens
parse() converts a path specification into a list of tokens, which can be
used to create a regular expression or path generating function.
final tokens = parse('/users/:id');
final regExp = tokensToRegExp(tokens);
final toPath = tokensToFunction(tokens);
Similar to pathToRegExp(), parameters can also be extracted during parsing.
final parameters = <String>[];
final tokens = parse('/users/:id', parameters: parameters);
If you intend to match and generate paths from the same path specification,
parse() and the token-based functions should be preferred to their path-based
counterparts. This is because the token-based functions can reuse the same
tokens, whereas each path-based function must parse the path specification anew.
Options
Prefix Matching
By default, a regular expression created by pathToRegExp or tokensToRegExp
matches the entire input. However, if the optional prefix argument is true, it
may also match as a prefix until a delimiter.
final regExp = pathToRegExp('/user/:id', prefix: true);
regExp.hasMatch('/user/12/details'); // => true
Case Sensitivity
By default, a regular expression created by pathToRegExp or tokensToRegExp
is case sensitive. To create a case insensitive regular expression, set
caseSensitive to false.
final regExp = pathToRegExp('/user/:id', caseSensitive: false);
regExp.hasMatch('/USER/12'); // => true