yoshuawuyts / sheet-router

fast, modular client-side router
MIT License
226 stars 18 forks source link

Route hierarchy #59

Open YerkoPalma opened 7 years ago

YerkoPalma commented 7 years ago

I'm building a toy app with sheet-router and yo-yo, I have this route defined.

const router = sheetRouter({ default: '/404' }, [
  [ '/posts', postsComponent,
    ['/new', newPostComponent],
    ['/:post', postComponent,
      ['/comments', commentsComponent]
    ]
  ],
  ['/404', (params) => html`<div>Oh no, path not found! ${JSON.stringify(params, null, 2)}</div>`],
])

With that I want the following behaviour

What I'm actually getting is

I though that if some route is not found, it would evaluate if some other route would match, and only if no one matched the given path show the default route.

So, is my code right for what I'm trying to achieve? Or am I misunderstanding how the router resolve paths?

Thanks in advance.

yoshuawuyts commented 7 years ago

Hmmmmmm, yeah this might have been the case at some point, but the way wayfarer's internals are right now are quite complex as-is to be honest. I'd be open for a PR that adds this behavior in wayfarer, on the sole condition that we test it well - I think supporting this is definitely reasonable