I'm working on a Hybrid Angular/AngularJS app. The main AppModule is Angular module that uses AppRoutingModule that uses a given state. Something like that:
AppModule:
imports: [AModule, BModule, AppRoutingModule, ...]
AppRoutingModule:
imports: [UIRouterUpgradeModule.forRoot(states: some_state)]
States:
export const some_state: [
{
name: 'a',
url: '/a'
views: {
main: {component: AComponent}
}
},
{
name: 'b',
url: '/b'
views: {
main: {component: BComponent}
}
}
]
What I want to do - say I'm in a BComponent, I want to navigate to AComponent. In a pure angular component I would use the Router from the RouterModule (forRoot in AppModule and forChild in child modules). Something like router.navigateToURL('...')
Now I'm using UIRouterUpgradeModule and I could not find how to do it. Any help will be great thanks!
In your component, first declare
router
in constructor like shown below :Then create a function that will be used whenever route change is required, you can bind this function to any event like button click to see required changes :