Newer Version Available
Migrate to lightning:isUrlAddressable from force:navigateToComponent
If you’re currently using the force:navigateToComponent event, you can provide backward compatibility for bookmarked links by redirecting requests to a component that uses lightning:isUrlAddressable.
First, copy your original component, including its definition, controller, helper, renderer, and CSS. Make the new component implement the lightning:isUrlAddressable interface.
Change the new component to read the values passed through the navigation request from cmp.get("v.pageReference").state.
In the new component, remove the attributes mapped from the URL that aren’t used to copy values from the page state in the component’s init handler.
Change the instances that navigate to your old component to the new API and address of your new component. For example, remove instances of force:navigateToComponent, like $A.get("e.force:navigateToComponent").setParams({componentDef: "c:oldCmp", attributes: {"myAttr": "foo"}}).fire();.
1cmp.find("navigationService").navigate({
2 type: "standard__component",
3 attributes: {
4 componentName: "c__myCmpCopy"
5 },
6 state: {
7 "c__myAttr": "foo"
8 }
9});1({
2 init: function(cmp, event, helper) {
3 cmp.find("navigation").navigate({
4 type: "standard__component",
5 attributes: {
6 componentName: "c__componentB" },
7 state: {
8 c__myAttr: cmp.get("v.myAttr")
9 }
10 }, true); // replace = true
11 }
12})