Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add doc for GetRouteURL #249

Merged
merged 4 commits into from Mar 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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