jamesddavies / lit-route

A client-side router for lit-html applications.
8 stars 2 forks source link

Default route? #1

Closed LasseRosenow closed 5 years ago

LasseRosenow commented 5 years ago

I really like this library and would like to implement it into my project, but I don't see a way to implement a default route for every path that is not defined in my routing.

Let's say I have this routing:

const Router = () => html ${new Route('/', () => Home(), true).mount()} ${new Route('/home', () => Home(), true).mount()} ${new Route('/news', () => News(), true).mount()} ``

But if if someone goes to "/fancypath" I would like to display something like 404 or just the home page. Can you think of any way to implement this specific behavior?

jamesddavies commented 5 years ago

Hi,

This is a great suggestion - I've just got some testing to do on an update that would include this feature, but it should be in by tonight/tomorrow morning. I'll leave a comment here when it's updated!

jamesddavies commented 5 years ago

This feature has now been added in version 0.4.3 - closing this issue. Give it a try and let me know how you get on!

LasseRosenow commented 5 years ago

Thanks a lot thats pretty nice :)

But there is just a small thing I realized: It seems like you have to put the DefaultRoute element as the last element. If you don't do so it will always be shown. Is that intended behavior?

jamesddavies commented 5 years ago

Yes that is the intended behaviour - all other routes need to be mounted before the DefaultRoute so it knows which routes are being used in your app. I'll update the documentation so that's a bit clearer. Thanks again!

LasseRosenow commented 5 years ago

Okay yeah I think updating the docs should do the job. Thanks a lot. I really didn't expect this to get sorted out by you so fast :)