Skip to content

Commit 07d351f

Browse files
Update Routing.md
1 parent 97f99c7 commit 07d351f

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Routing.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ app.all("/", function (req, res) {
111111

112112
Routejs supports route parameters, route parameters are used for dynamic routing.
113113

114-
In routejs we can define route parameters using `{}` syntax, we can put any name inside curly brackets and we can access them using `req.params` object.
114+
In routejs we can define route parameters using `:` syntax, we can put any name inside curly brackets and we can access them using `req.params` object.
115115

116116
Example:
117117

118118
```js
119-
app.get("/user/{name}", function (req, res) {
119+
app.get("/user/:name", function (req, res) {
120120
// Get route parameters using params object
121121
res.end(req.params.name);
122122
});
@@ -141,7 +141,7 @@ Make sure to escape all regular expression special characters, otherwise you mig
141141

142142
Named regular expression:
143143
```js
144-
app.get("/user/{id:(\\d+)}", function (req, res) {
144+
app.get("/user/:id:(\\d+)", function (req, res) {
145145
res.end(req.params.id);
146146
});
147147
```
@@ -235,7 +235,7 @@ If you are using host based url routing, please make sure to set the default hos
235235
Set default host to all routes and middlewares:
236236
```js
237237
const app = new Router({
238-
host: "localhost:3000"
238+
host: "localhost"
239239
});
240240
```
241241

@@ -244,13 +244,13 @@ If we set default request host to all routes and middlewares, then they are only
244244
Example:
245245

246246
```js
247-
// Route is only executed when request host is localhost:3000
247+
// Route is only executed when request host is localhost
248248
app.get("/", function (req, res) {
249249
res.end("Ok");
250250
});
251251

252-
// Route is only executed when request host is blog.localhost:3000
253-
app.domain("blog.localhost:3000", function (router) {
252+
// Route is only executed when request host is blog.localhost
253+
app.domain("blog.localhost", function (router) {
254254
router.get("/", function (req, res) {
255255
res.end("Blog");
256256
});
@@ -262,7 +262,7 @@ Host parameters:
262262
Routejs supports named parameters and regular expression in host based url routing.
263263

264264
```js
265-
app.domain("{name}.localhost:3000", function (router) {
265+
app.domain(":name.localhost", function (router) {
266266
router.get("/", function (req, res) {
267267
res.end(req.subdomains.name);
268268
});

0 commit comments

Comments
 (0)