<p dir="auto">Hello,</p>
<p dir="auto">I want to propose to you to extend router url_parser in angular, to make it smarter.</p>
<p dir="auto">On a big projects, I have to deal with complex routes which have optional params and I want to work only with one route and also keep it simple and clean, also I don't want duplicated urls or empty segments in them or something like that.</p>
<p dir="auto">For example, if I have a pagination on the page <code class="notranslate">/cars</code>, I can access the same page via <code class="notranslate">/cars</code> or <code class="notranslate">/cars/page-2</code>. Also I don't want to have url like <code class="notranslate">/cars/page-1</code> because it is the same as <code class="notranslate">/cars</code>.</p>
<p dir="auto">To avoid this kind of problems, I made for my backend framework a smarter routes which resolve all issues which I described above, and I will be happy if you will implement it too in the standard angular router to make all the community happier.</p>
<p dir="auto">I have made them in that way:</p>
<ol dir="auto">
<li><code class="notranslate">{&lt;paramName&gt;?:&lt;defaultValue&gt;|&lt;regex&gt;}?</code> - You can define a parameter which may be optional, with a default value and restrict it by regex, or just add "?" symbol at the end of <code class="notranslate">paramName</code>, to make it greedy(for example <code class="notranslate">{systemName?}</code> is equal to <code class="notranslate">(.+?)</code>, <code class="notranslate">{systemName?}?</code> is equal to <code class="notranslate">(.+?)?</code>).</li>
<li><code class="notranslate">[&lt;optionalRouteSegment&gt;]</code> - You can define an optional part of the route if it would not be valid in the segment from the inside. This syntax goes recursively. For example <code class="notranslate">[/engine/{engineName}[/year/{engineYear}]/v/{engineVersion}]</code></li>
</ol>
<p dir="auto">For example I have a route with syntax <code class="notranslate">/cars[/category/{categoryName?}][/page/{page:1|[1-9][0-9]*}]</code>.</p>
<p dir="auto"><code class="notranslate">categoryName</code> is greedy and required in his segment and could be any symbol. If it does't exists, all the segment will disappear. Why greedy? Because it has an optional segment after, which will match if you will not set the greedy.<br>
<code class="notranslate">page</code> is also required in his segment, has a default value and could be any number which starts from <code class="notranslate">1</code>.</p>
<p dir="auto">It will be valid via next urls:</p>
<ol dir="auto">
<li>If i call it with no params or with <code class="notranslate">{page: 1}</code>, i will get <code class="notranslate">/cars</code>, because it doesn't have <code class="notranslate">categoryName</code> and the <code class="notranslate">page</code> value is the same as default value.</li>
<li>If i call it with <code class="notranslate">{page: 2}</code>, i will get <code class="notranslate">/cars/page/2</code>.</li>
<li>If i call it with <code class="notranslate">{categoryName: 'supercar'}</code> or with <code class="notranslate">{categoryName: 'supercar', page: 1}</code>, I will get <code class="notranslate">/cars/category/supercar</code>.</li>
<li>If i call it with <code class="notranslate">{categoryName: 'supercar', page: 2}</code>, I will get <code class="notranslate">/cars/category/supercar/page/2</code>.</li>
</ol>
<p dir="auto">You get the idea how smart can they be? And this is a big plus for the seo.</p>
<p dir="auto">Cheers.</p>
<p dir="auto"><strong>I'm submitting a ...</strong>  (check one with "x")</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[ ] bug report =&gt; search github for a similar issue or PR before submitting
[x] feature request
[ ] support request =&gt; Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question"><pre class="notranslate"><code class="notranslate">[ ] bug report =&gt; search github for a similar issue or PR before submitting
[x] feature request
[ ] support request =&gt; Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
</code></pre></div>
<p dir="auto"><strong>Current behavior</strong></p>

<p dir="auto">Human readable error text is informative only and can't be minified for production build. This text does not compress well with gzip.</p>
<p dir="auto"><strong>Expected behavior</strong></p>

<p dir="auto">Suggest moving this informative error text to console.error() to work well with UglifyJS drop_console.</p>
<p dir="auto"><strong>Minimal reproduction of the problem with instructions</strong></p>

<p dir="auto">From<br>
new Error("long informative error message...")<br>
To<br>
console.error("long informative error message...")<br>
new Error()</p>
<p dir="auto"><strong>What is the motivation / use case for changing the behavior?</strong></p>

<p dir="auto">Informative-only error strings are verbose and cannot be dropped in minification.<br>
Suggest moving most informative-only human-readable text to console.error() to work well with UglifyJS options drop_console. It might not be significant, but minification saving may be 4 or 5 KB for total build.<br>
Top affected files are:<br>
./forms/src/directives/error_examples.ts (1217 bytes of informative text)<br>
./forms/src/directives/reactive_error.ts (1286 bytes of informative text)<br>
./forms/src/directives/template_driven_errors.ts (1415 bytes of informative text)<br>
./common/src/facade/errors.ts<br>
./core/src/di/reflective_errors.ts<br>
./core/src/facade/errors.ts<br>
./core/testing/facade/errors.ts</p>
<p dir="auto"><strong>Please tell us about your environment:</strong></p>

<p dir="auto">Windows 7</p>
<ul dir="auto">
<li><strong>Angular version:</strong> 2.0.X</li>
</ul>

<p dir="auto">2.4.9</p>
<ul dir="auto">
<li><strong>Browser:</strong> [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]</li>
</ul>

<p dir="auto">all</p>
<ul dir="auto">
<li>
<p dir="auto"><strong>Language:</strong> [all | TypeScript X.X | ES6/7 | ES5]<br>
Typescript<br>
Webpack AOT<br>
UglifyJS minify compiler</p>
</li>
<li>
<p dir="auto"><strong>Node (for AoT issues):</strong> <code class="notranslate">node --version</code> =<br>
7.2.1</p>
</li>
</ul>