My app is widely using NavLink and NavigateAction. In some pages I would like to display the link to the "parent page", for example if a user views the Customers List page and clicks the link that opens the specific Customer page, I would like to display the link that leads back to "Customers List". RouteStore only exposes the current route, but not a previous route, so I have to use the following work-around for now for the flexible and once-for-all solution:
Extend RouteStore to keep info of the navigate[type=click] source.
Modify NavLink so that it dispatches 'NAVIGATE_CLICK' message before executing navigateAction:
var dispatchMessageAction = function(context, payload, done) {
context.dispatch(payload.messageName, payload.messageBody, done);
};
var routeStore = context.getStore('RouteStore');
if (routeStore && routeStore.getCurrentRoute) {
var currentRoute = routeStore.getCurrentRoute();
context.executeAction(dispatchMessageAction, {
messageName : 'NAVIGATE_CLICK',
messageBody : currentRoute
})
}
Get the "parent route" in Customer page and show the back link if it's applicable:
if(routeStore && routeStore.getRouteBeforeClick){
var parentRoute = routeStore.getRouteBeforeClick();
if(parentRoute){
// add another NavLink that leads to the prev route.
}
}
Though it does not seem to be very elegant to me...Could anyone comment on this? Is it OK solution? Is there better approach? Thanks!
My app is widely using NavLink and NavigateAction. In some pages I would like to display the link to the "parent page", for example if a user views the Customers List page and clicks the link that opens the specific Customer page, I would like to display the link that leads back to "Customers List". RouteStore only exposes the current route, but not a previous route, so I have to use the following work-around for now for the flexible and once-for-all solution:
Though it does not seem to be very elegant to me...Could anyone comment on this? Is it OK solution? Is there better approach? Thanks!