Fix incorrect params when building controller redirect route url.
This commit is contained in:
parent
c0a7c9e3b1
commit
bfe56d7a31
2 changed files with 7 additions and 3 deletions
|
|
@ -152,7 +152,7 @@ func (c *Controller) cachePage(ctx echo.Context, page Page, html *bytes.Buffer)
|
||||||
|
|
||||||
// Redirect redirects to a given route name with optional route parameters
|
// Redirect redirects to a given route name with optional route parameters
|
||||||
func (c *Controller) Redirect(ctx echo.Context, route string, routeParams ...interface{}) error {
|
func (c *Controller) Redirect(ctx echo.Context, route string, routeParams ...interface{}) error {
|
||||||
url := ctx.Echo().Reverse(route, routeParams)
|
url := ctx.Echo().Reverse(route, routeParams...)
|
||||||
|
|
||||||
if htmx.GetRequest(ctx).Boosted {
|
if htmx.GetRequest(ctx).Boosted {
|
||||||
htmx.Response{
|
htmx.Response{
|
||||||
|
|
|
||||||
|
|
@ -43,11 +43,15 @@ func TestMain(m *testing.M) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestController_Redirect(t *testing.T) {
|
func TestController_Redirect(t *testing.T) {
|
||||||
|
c.Web.GET("/path/:first/and/:second", func(c echo.Context) error {
|
||||||
|
return nil
|
||||||
|
}).Name = "redirect-test"
|
||||||
|
|
||||||
ctx, _ := tests.NewContext(c.Web, "/abc")
|
ctx, _ := tests.NewContext(c.Web, "/abc")
|
||||||
ctr := NewController(c)
|
ctr := NewController(c)
|
||||||
err := ctr.Redirect(ctx, "home")
|
err := ctr.Redirect(ctx, "redirect-test", "one", "two")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "", ctx.Response().Header().Get(echo.HeaderLocation))
|
assert.Equal(t, "/path/one/and/two", ctx.Response().Header().Get(echo.HeaderLocation))
|
||||||
assert.Equal(t, http.StatusFound, ctx.Response().Status)
|
assert.Equal(t, http.StatusFound, ctx.Response().Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue