Skip to content

Commit

Permalink
Merge pull request #249 from sujit-baniya/master
Browse files Browse the repository at this point in the history
Add doc for GetRouteURL
  • Loading branch information
ReneWerner87 committed Mar 30, 2022
2 parents 5976412 + d335ad2 commit 05b94bf
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions api/ctx.md
Expand Up @@ -587,6 +587,35 @@ func (c *Ctx) GetRespHeaders() map[string]string
```
{% endcode %}

## GetRouteURL

Generates URLs to named routes, with parameters. URLs are relative, for example: "/user/1831"

{% code title="Signature" %}
```go
func (c *Ctx) GetRouteURL(routeName string, params Map) (string, error)
```
{% endcode %}

{% code title="Example" %}
```go
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Home page")
}).Name("home")
app.Get("/user/:id", func(c *fiber.Ctx) error {
return c.SendString(c.Params("id"))
}).Name("user.show")
app.Get("/test", func(c *fiber.Ctx) error {
location, _ := c.GetRouteURL("user.show", fiber.Map{"id": 1})
return c.SendString(location)
})
// /test returns "/user/1"
```
{% endcode %}

## Hostname

Returns the hostname derived from the [Host](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Host) HTTP header.
Expand Down

0 comments on commit 05b94bf

Please sign in to comment.