i have a component which is used in different screens in the application. I have a back button in this shared component. As I navigate to this component from different other components, when i click Back button in shared component, i need to route back to the screen from where I routed to the shared component. For example: S is my shared component to which I navigate from A, B, C and D screens/components. Now, when I click back button in shared component, I need to go back to the component from where I routed to the shared one. Is there any solution to this or any idea how to do this?
Asked
Active
Viewed 46 times
-3
-
2Possible duplicate of [How to go back last page](https://stackoverflow.com/questions/35446955/how-to-go-back-last-page) – EmandM Jun 15 '18 at 06:43
-
I have to navigate between components of different modules. and this solution is not working in this case. – Sam Jun 15 '18 at 07:23
-
Use Router.url to know in wich route you are, or a @Input in your component – Eliseo Jun 15 '18 at 07:38
1 Answers
0
You can use browser back like so.
@Component({
...
})
class SharedComponent {
constructor(private location: Location) {
}
back() {
this.location.back();
}
}

Pavan Bahuguni
- 1,947
- 1
- 15
- 21
-
this solution is not working in my case. if I am applying this, screen is getting navigated to the module which i initially opened but not to the one from where i navigated to the shared component. – Sam Jun 15 '18 at 07:25