Hi all,
For those in the Anvil User Group Meeting you would have seen my short demo on a new routing dependency.
There wasn’t nearly enough time to showcase all the features,
so here’s a few more details
Key Features :
True URL-based Routing: Utilizes actual URLs instead of hash-based navigation
Meta tag support for more SEO-friendly routes
Works with layouts, for consistent UI structures across routes.
Server-Side Data Loading: improves initial page load times by serving the page and data together.
Intelligent Caching APIs to make your apps feel faster.
Smart Navigation Links: Provides enhanced link components that integrate with the routing system for smooth, efficient navigation.
Docs :
https://routing-docs.anvil.works
Source Code :
https://github.com/anvil-works/routing
3rd Party ID :
3PIDO5P3H4VPEMPL
Clone (M3 example):
It’s very much in beta, and subject to breaking changes, but it’s ready to play
6 Likes
This is a thing of beauty
1 Like
How does this relate to the new anvil.server.route
functionality? I see in the example that that decorator is never used.
Does this add on to that functionality?
Yes - there’s some notes in the docs about it
https://routing-docs.anvil.works/routes/#server-routes
In order for server routes to work you need to import your routes into a server module
# Server_Routes.py
from . import routes
And when you import your routes into a server module this will create anvil.server.routes
based upon the routes you defined.
The actual source code for this is here:
routing/client_code/router/_route.py at master · anvil-works/routing · GitHub
Here is some pseudo code
create_server_route(cls):
if cls.path is None:
return
@anvil.server.route(cls.path)
def route_handler(*args, **kws):
...
# server an app response
class Route:
def __init_subclass__(cls):
if anvil.is_server_side():
create_server_route(cls)
stucork
Split this topic
October 30, 2024, 11:23am
6
A post was split to a new topic: Anvil.server.route in uplink
Going to use this in my new mini app. Can’t wait to see how it works!
2 Likes
So far much cleaner than hash routing. I had to fiddle a bit to translate some of the concepts for navigating and caching, passing query parameters etc. but so far so good.
Bonus points for not making me migrate to layouts and allowing for template forms and route forms!! The migration would have been much harder if I had to use layouts too.
1 Like
stucork
October 30, 2024, 11:02pm
9
Good effort! Please add to any of the migration docs if anything was confusing or would have been helpful.
1 Like