Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return to previous page with parameters?

Tags:

angular

I want to return to previous page with some parameters. Any suggestion how can i do that?

import {Location} from '@angular/common';
   returnToPreviousPage(){
        this._location.back();
    }

So what i want is something like this :

this._location.back(id:123);

And when i back on page to have something like this : www.test.com?d=123

like image 798
None Avatar asked Jun 19 '17 10:06

None


1 Answers

Here if you are using the this._location.back() to go back you can pass only the index to this function. How much index you want to go back from browser history.

For Example to go 2 index back

this._location.back(2);

Example to go back with queryParams

this.router.navigate(['/test2', { id: 12321313}]);

Check for angular 2 declaration function location.back() inside @angular\common.js

class Location {
     /* Navigates back in the platform's history.*/
     /* @return {?} */

    back() { this._platformStrategy.back(); }
 }

InShort the thing what you are trying this._location.back(2) work same as window.history.back(); and accept only the index value you want to go back from browser history

like image 54
mayur Avatar answered Sep 20 '22 18:09

mayur