-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for nested routing #6
Comments
Wouldn't it be easier to just do: var mainRoute = Router.GoTo<viewmodelT>();
var subRoute = Router.Goto<subViewmodelT>();
mainRoute.SelectedChild = subRoute; However I already thought of having some extensions to make:
Is there an example project where I could read some code about what you are trying to achieve? |
Yeah so basically, (and ill be using vue-router as an example here even tho its a web framework it fits the case here i think) In vue, you define your routes and their components (views/viewmodels) from the app settings (DI container in .net) from there you can define children for them as well. Instead of having a regular ContentControl that just binds directly to the current route of the view, it has a special usercontrol that not only binds the content to it, but also is aware of where inside of the routing hierarchy it is. But ofcourse with the way the routing is based on viewmodels in c# you dont really need to specify subroutes at DI level if you can just do it at Router.GoTo time. so i have a route like
So lets say i have my parent window with a router view, it would show the TopLevel route inside of it, and if whatever is inside of there has another router view in it, that would show the viewmodel of the first child, that one could have another on inside it etc. to see how vue-router does it: const routes = [
{
path: '/user/:id',
component: User,
children: [
{
// UserProfile will be rendered inside User's <router-view>
// when /user/:id/profile is matched
path: 'profile',
component: UserProfile,
},
{
// UserPosts will be rendered inside User's <router-view>
// when /user/:id/posts is matched
path: 'posts',
component: UserPosts,
},
],
},
] which defines the routes (and arguments in a web scenario) and then the component (view/viewmodel) then, everywhere u want nested routes: <router-view "/> which binds to the route recursively based on which viewmodel it is in the hierarchy, so the Parentviewmodels router view will have a content binding of the child routes viemodel, that one of its child etc. for a better understanding i will just show the vue router docs: hopefully this gives u an idea of what i mean. This would be amazing for this framework as its a very simple thing to add and would make it alot more functional especially in apps with sub navigation like tabs, nav bars etc. another cooll thing from vue-router is the router-link: <nav>
<RouterLink to="/">Go to Home</RouterLink>
<RouterLink to="/about">Go to About</RouterLink>
</nav> which is a wrapping for any kind of control that makes it so that when it is clicked like a button, it will forwards to the route specified (which means you can do direct bindings with no code behind necessary for quick and dirty routes) it could look like this in avalonia: <RouterLink To="{Binding ViewModelTypeHere}/> |
For simplicity sake lets say the RouterView Usercontrol just looks like this
then that routerview would have some code in it that scans all if(IsRoot){
//Some function to get the Top Level route from the Router
//Some function to scan if the currently loaded routes view contains another Routerview, if so, pass it the router, and an index counter recursively so it knows which route in the hierarchy it is
} |
I don't think that this Maybe you have some |
Wow thanks for your effort , I try to take a look in the next days... May take some time. |
No worries mate! love this project as its my go to router for smaller avalonia apps so i really hope these things can be worked on. I am also willing to contribute if you need it!. |
This one is a big bit and completely understandable if out of scope but i really like this library but theres one thing ive always felt was missing for apps that have subviews.
Nested routing.
Comparing it to routing libraries like vue router or the react routers
a nested routing solution inside this library would be amazing and would make this the perfect replacement for ReactiveUis router.
The way this would have to be implemented (again, comparing it to vue -router) is that when creating your IOC container you would do something like this
then when routing it i could for example do something like this
as usual
and the router could have some kind of property like CurrentRoute.SelectedChild to bind to which we can then bind in the subview
The text was updated successfully, but these errors were encountered: