From: Jonathan Date: Thu, 24 Feb 2022 21:39:56 +0000 (+0100) Subject: Rephrase Regexp to regular expression (#1321) X-Git-Tag: v4.0.13~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=322402a1f4a812bebafbe8f13d3f0a87f2743aee;p=thirdparty%2Fvuejs%2Frouter.git Rephrase Regexp to regular expression (#1321) * Rephrase Regexp to regular expression `RegExp` is the name of the object in JavaScript. The word "regex" is more generic and a shorthand for "regular expression". * Update route-matching-syntax.md --- diff --git a/docs/guide/essentials/route-matching-syntax.md b/docs/guide/essentials/route-matching-syntax.md index 9f7d3e98..d61fea32 100644 --- a/docs/guide/essentials/route-matching-syntax.md +++ b/docs/guide/essentials/route-matching-syntax.md @@ -6,9 +6,9 @@ Most applications will use static routes like `/about` and dynamic routes like ` For the sake of simplicity, all route records **are omitting the `component` property** to focus on the `path` value. ::: -## Custom Regexp in params +## Custom regex in params -When defining a param like `:userId`, we internally use the following regexp `([^/]+)` (at least one character that isn't a slash `/`) to extract params from URLs. This works well unless you need to differentiate two routes based on the param content. Imagine two routes `/:orderId` and `/:productName`, both would match the exact same URLs, so we need a way to differentiate them. The easiest way would be to add a static section to the path that differentiates them: +When defining a param like `:userId`, we internally use the following regex `([^/]+)` (at least one character that isn't a slash `/`) to extract params from URLs. This works well unless you need to differentiate two routes based on the param content. Imagine two routes `/:orderId` and `/:productName`, both would match the exact same URLs, so we need a way to differentiate them. The easiest way would be to add a static section to the path that differentiates them: ```js const routes = [ @@ -19,7 +19,7 @@ const routes = [ ] ``` -But in some scenarios we don't want to add that static section `/o`/`p`. However, `orderId` is always a number while `productName` can be anything, so we can specify a custom regexp for a param in parentheses: +But in some scenarios we don't want to add that static section `/o`/`p`. However, `orderId` is always a number while `productName` can be anything, so we can specify a custom regex for a param in parentheses: ```js const routes = [ @@ -63,7 +63,7 @@ router.resolve({ name: 'chapters', params: { chapters: [] } }).href // throws an Error because `chapters` is empty ``` -These can also be combined with custom Regexp by adding them **after the closing parentheses**: +These can also be combined with a custom regex by adding them **after the closing parentheses**: ```js const routes = [ @@ -111,4 +111,4 @@ Note that `*` technically also marks a parameter as optional but `?` parameters ## Debugging -If you need to dig how your routes are transformed into Regexp to understand why a route isn't being matched or, to report a bug, you can use the [path ranker tool](https://paths.esm.dev/?p=AAMeJSyAwR4UbFDAFxAcAGAIJXMAAA..#). It supports sharing your routes through the URL. +If you need to dig how your routes are transformed into a regex to understand why a route isn't being matched or, to report a bug, you can use the [path ranker tool](https://paths.esm.dev/?p=AAMeJSyAwR4UbFDAFxAcAGAIJXMAAA..#). It supports sharing your routes through the URL.