diff --git a/default_router.go b/default_router.go index b39b533..46c7978 100644 --- a/default_router.go +++ b/default_router.go @@ -50,7 +50,7 @@ func (r *DefaultRouter) GetStaticRoutes() []*StaticRoute { func (r *DefaultRouter) addRoute(m, p string, h Handler) { if r.prefix != "" { - p = fmt.Sprintf("/%s/%s", strings.TrimPrefix(r.prefix, "/"), strings.TrimSuffix(p, "/")) + p = fmt.Sprintf("/%s/%s", strings.Trim(r.prefix, "/"), strings.Trim(p, "/")) } r.Routes = append(r.Routes, &Route{ diff --git a/default_router_test.go b/default_router_test.go index 26724cb..4bdb9f4 100644 --- a/default_router_test.go +++ b/default_router_test.go @@ -38,12 +38,13 @@ func Test_Prefix_Route_Creation(t *testing.T) { r := require.New(t) router := tuu.NewRouter() - router.Prefix("/prefix") + router.Prefix("/prefix/") router.GET("/home", func(ctx tuu.Context) error { return nil }) - + router.GET("/home/about-us/", func(ctx tuu.Context) error { return nil }) routes := router.GetRoutes() - r.Len(routes, 1) - route := routes[0] - r.Contains(route.Path, "/prefix") + r.Len(routes, 2) + for _, route := range routes { + r.Contains(route.Path, "/prefix/home") + } }