fasthttp / router

Router implementation for fasthttp
BSD 3-Clause "New" or "Revised" License
463 stars 47 forks source link

wildcard segment ':slug' conflicts with existing children in path '/:slug' #20

Closed toby3d closed 4 years ago

toby3d commented 4 years ago

Same as buaazp/fasthttprouter#49.

I want use / path for render index page and /:slug for render specific content by it's :slug. I am aware about the hack through router.NotFound, but, firstly, this is not most obvious way, and secondly, it requires additional validations for the correct transitions between the necessary pages.

Example

func main() {
    ...

    r := router.New()
    handler.RegisterAPI(r.Group("/api")) // api
    handler.RegisterTemplates(r) // renders
}

func (h *MyHandlers) RegisterTemplates(g *router.Router) {
    g.GET("/", h.RenderIndex)
    g.GET("/:slug", h.RenderSlug)
}

func (h *MyHandlers) RegisterAPI(g *router.Router) {
    g.GET("/", h.ShowAll)
    g.GET("/:slug", h.ShowOne)
}
savsgio commented 4 years ago

Hi @toby3d,

I will try to discover the error and i will fix it.

Thanks for issue.

savsgio commented 4 years ago

Hi @toby3d,

Which values could have the :slug parameter?

toby3d commented 4 years ago

Any alphanum combinations and '-', like: 'hello-world', 'answer42', '300-is-not-200' and so on.

In general, I expect that any parameter in the root (/:slug, /:page/raw, /:player/vs/:enemy and etc.) will work same as any other parameters in any other routes (/user/:user, /hello/:first/:last).

savsgio commented 4 years ago

I'm researching about the issue. When I have something, I will tell here.

savsgio commented 4 years ago

I'm working for make the router more flexible, but i will take a few more days.

@toby3d

toby3d commented 4 years ago

@savsgio That's ok, take your time. 👍🏻

savsgio commented 4 years ago

I've been fixed it on branch master.

Soon, i will release a new version!

Thanks