You could move between view states by creating and replacing components.
Server-side Controller
public class LightningController {
@AuraEnabled
public static list<Account> getAccounts(){
return [SELECT Id, Name FROM Account LIMIT 10];
}
@AuraEnabled
public static list<Opportunity> getOpportunities(Id AccountId){
return [SELECT Id, Name FROM Opportunity WHERE AccountId = :AccountId];
}
}
App
<aura:application controller="LightningController" >
<aura:attribute type="Account[]" name="AccountList" />
<aura:handler name="init" value="{!this}" action="c.doInit" />
<aura:handler event="analysis:ATOEvent" action="{!c.ato}" />
<aura:handler event="analysis:OTAEvent" action="{!c.ota}" />
{!v.body}
</aura:application>
App client-side controller
({
doInit : function(component, event, helper){
var action = component.get("c.getAccounts");
action.setCallback(this,function(response){
if (response.getState() === "SUCCESS"){
component.set("{!v.AccountList}",response.getReturnValue());
helper.generateAccountList(component);
}
}
);
$A.enqueueAction(action);
},
ato : function(component, event, helper){
var action = component.get("c.getOpportunities");
action.setParams({"AccountId" : event.getParam("AccountId")});
action.setCallback(this,function(response){
if (response.getState() === "SUCCESS"){
helper.generateOpportunityList(component, response.getReturnValue());
}
}
);
$A.enqueueAction(action);
},
ota : function(component, event, helper){
helper.generateAccountList(component);
}
})
App helper
({
generateAccountList : function(component) {
$A.createComponent(
"analysis:AccountList",
{
"AccountList" : component.get("{!v.AccountList}")
},
function(newComponent){
component.set("v.body",newComponent);
}
)
},
generateOpportunityList : function(component, OpportunityList){
$A.createComponent(
"analysis:OpportunityList",
{
"OpportunityList" : OpportunityList
},
function(newComponent){
component.set("v.body",newComponent);
}
)
}
})
AccountList
<aura:component >
<aura:registerEvent name="ATOEvent" type="analysis:ATOEvent" />
<aura:attribute name="AccountList" type="Account[]" />
<aura:iteration items="{!v.AccountList}" var="Account">
<ui:outputText value="{!Account.Name}" />
<ui:button label="go" press="c.fireato" buttonTitle="{!Account.Id}" />
<br/>
</aura:iteration>
</aura:component>
AccountListController
({
fireato : function(component, event, helper) {
var action = $A.get("e.analysis:ATOEvent");
action.setParams({"AccountId" : event.getSource().get("{!v.buttonTitle}")});
action.fire();
}
})
OpportunityList
<aura:component >
<aura:registerEvent name="OTAEvent" type="analysis:OTAEvent" />
<aura:attribute type="Opportunity[]" name="OpportunityList" />
<ui:button label="Go Back" press="c.fireota" />
<aura:iteration items="{!v.OpportunityList}" var="Opportunity" >
<br />
<ui:outputText value="{!Opportunity.Name}" />
</aura:iteration>
</aura:component>
OpportunityListController
({
fireota : function(component, event, helper) {
var action = $A.get("e.analysis:OTAEvent");
action.fire();
}
})
ATOEvent
<aura:event type="APPLICATION" description="ATOEvent" >
<aura:attribute name="AccountId" type="Id" />
</aura:event>
OTAEvent
<aura:event type="APPLICATION" description="OTAEvent" />