Control passing docs
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent da84c0b · Browse files · 3 files·+81 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+81 added−0 removed
- other:+81 added−0 removed
Provenance
- Commit
548a070- Tree
329bacc- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
da84c0b
3 files changed+81 added−0 removed
modified:docs/migrate.1+34 added
103 unmodified lines104 .105 .fi106 .107 .IP "" 0108+.109+.SS "Passing Route Control"110+Old express had a weak notion of route passing, which did not support async, and was never properly implemented for practical use:111+.112+.IP "" 4113+.114+.nf115 116+get(\'/\', function(){117+ this\.pass(\'/foobar\');118+});119+.120+.fi121+.122+.IP "" 0123+.124+.P125+Now Express has access to Connect\'s \fBnext()\fR function, which is passed as the fourth and final argument\. Calling \fBnext()\fR will pass control to the next \fImatching route\fR, or continue down the stack of Connect middleware\.126+.127+.IP "" 4128+.129+.nf130+131+app\.get(\'/user/:id?\', function(req, res, params, next){132+ next();133+});134+135+app\.get(\'/user\', function(){136+ // \.\.\. respond137+});138+.139+.fi140+.141+.IP "" 0142+modified:docs/migrate.html+25 added
218 unmodified lines219 params.id;220 });221 </code></pre>222 223+<h3 id="Passing-Route-Control">Passing Route Control</h3>224+225+<p>Old express had a weak notion of route passing,226+which did not support async, and was never properly227+implemented for practical use:</p>228+229+<pre><code>get('/', function(){230+ this.pass('/foobar');231+});232+</code></pre>233+234+<p>Now Express has access to Connect's <code>next()</code> function,235+which is passed as the fourth and final argument. Calling <code>next()</code> will236+pass control to the next <em>matching route</em>, or continue down the stack237+of Connect middleware.</p>238+239+<pre><code>app.get('/user/:id?', function(req, res, params, next){240+ next();241+});242+243+app.get('/user', function(){244+ // ... respond245+});246+</code></pre>247+248 </div>249 </div>250 </div>251 </body>1 unmodified linemodified:docs/migrate.md+22 added
61 unmodified lines626364656667686970717273747576777879808182838485868761 unmodified lines app.get('/user/:id', function(req, res, params){ params.id; });
### Passing Route Control
Old express had a weak notion of route passing,which did not support async, and was never properly implemented for practical use:
get('/', function(){ this.pass('/foobar'); });
Now Express has access to Connect's `next()` function,which is passed as the fourth and final argument. Calling `next()` willpass control to the next _matching route_, or continue down the stackof Connect middleware.
app.get('/user/:id?', function(req, res, params, next){ next(); });
app.get('/user', function(){ // ... respond });No newline at end of file