From 736857b76debbdeb9bc194c7815a6a0a4e5e6f1b Mon Sep 17 00:00:00 2001 From: Sujit Date: Tue, 22 Mar 2022 00:05:13 +0545 Subject: [PATCH 1/4] Add doc for GetRouteURL --- api/ctx.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/api/ctx.md b/api/ctx.md index f03da977c76..356dd9732fa 100644 --- a/api/ctx.md +++ b/api/ctx.md @@ -1302,6 +1302,31 @@ app.Get("/back", func(c *fiber.Ctx) error { ``` {% endcode %} +## GetRouteURL + +Get URI of route by route name and parameters + +{% 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) +}) +``` +{% endcode %} + ## Render Renders a view with data and sends a `text/html` response. By default `Render` uses the default [**Go Template engine**](https://golang.org/pkg/html/template/). If you want to use another View engine, please take a look at our [**Template middleware**](https://github.com/gofiber/template). From 3b79fa96d2ec66b5699d4070044a6cd94df8fce8 Mon Sep 17 00:00:00 2001 From: Sujit Baniya Date: Tue, 22 Mar 2022 08:46:19 +0545 Subject: [PATCH 2/4] Update api/ctx.md Co-authored-by: hi019 <65871571+hi019@users.noreply.github.com> --- api/ctx.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/api/ctx.md b/api/ctx.md index 356dd9732fa..d9ce1fbacea 100644 --- a/api/ctx.md +++ b/api/ctx.md @@ -1316,14 +1316,18 @@ func (c *Ctx) GetRouteURL(routeName string, params Map) (string, error) ```go app.Get("/", func(c *fiber.Ctx) error { return c.SendString("Home page") -}).Name("Home") +}).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 %} From ced3474743abc8e1b54ce6c102a4720bf306d951 Mon Sep 17 00:00:00 2001 From: Sujit Baniya Date: Tue, 22 Mar 2022 08:46:36 +0545 Subject: [PATCH 3/4] Update api/ctx.md Co-authored-by: hi019 <65871571+hi019@users.noreply.github.com> --- api/ctx.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/ctx.md b/api/ctx.md index d9ce1fbacea..802e0eda177 100644 --- a/api/ctx.md +++ b/api/ctx.md @@ -1304,7 +1304,7 @@ app.Get("/back", func(c *fiber.Ctx) error { ## GetRouteURL -Get URI of route by route name and parameters +Generates URLs to named routes, with parameters. URLs are relative, for example: "/user/1831" {% code title="Signature" %} ```go From d335ad27d030f9c119ea08dd77695ed1a0866abe Mon Sep 17 00:00:00 2001 From: wernerr Date: Wed, 30 Mar 2022 10:10:18 +0200 Subject: [PATCH 4/4] Update doc for GetRouteURL --- api/ctx.md | 58 +++++++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/api/ctx.md b/api/ctx.md index 802e0eda177..1a6c3b99c25 100644 --- a/api/ctx.md +++ b/api/ctx.md @@ -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. @@ -1302,35 +1331,6 @@ app.Get("/back", func(c *fiber.Ctx) error { ``` {% 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 %} - ## Render Renders a view with data and sends a `text/html` response. By default `Render` uses the default [**Go Template engine**](https://golang.org/pkg/html/template/). If you want to use another View engine, please take a look at our [**Template middleware**](https://github.com/gofiber/template).