This is an example from documentation
I added data to route configuration:
data: { data1: "data1" }
and when I’m trying access this data, I get data: undefined.
and when I’m trying access this data, I get data: undefined.
Where are you trying to access this data
?
I have same problem. I am trying to access it in global lifecyclehook ‘canLoad’ function.
is the lifecycle on the view model, or on a lifecycle hook?
If it’s on the view model, then it’s a bug, but this is a very basic usage, I think it’s unlikely to be a bug.
If it’s on a lifecycle hook, then params is the 2nd argument, the 1st argument is the view model instance the hook is invoked on.
Maybe paste some code here so we can see why easier?
It’s on a lifecycle hook, here is my code. (from docs)
@lifecycleHooks()
class AuthHandler {
canLoad(viewModel, params: Parameters, instruction: RoutingInstruction, navigation: Navigation) {
console.log("params",params);
console.log("navigation",navigation);
return true;
}
}
The output of params is ‘{}’ ,
The output of navigation is an object , but it’s ‘data’ property is undefined. I think I should use this, not params, right?
This is my route configuration
static routes: IRoute[] = [
{
path: ['login-page'],
component: LoginPage,
title: 'Login',
},
{
path: ['main'],
component: ContentPage,
title: 'Content 2',
data: { auth: true }
}
]
Thanks for your help.
Try renaming data
to parameters
{
path: ['main'],
component: ContentPage,
title: 'Content 2',
parameters: { auth: true }
}
I think the current documentation is mixing router-lite
and router
logic.
Thanks, it works with parameters!
I switched to router-lite now, because I think it’s documentation is more accurate and api is cleaner. Thanks any way!