title: Redirect to Previous Page In Angular
body: <p>I have installed a package called ngx-pagination. But i have a problem since when you navigate away from the previous page and you click the back button, it redirects you to the first page instead of going back to the previous page? How can i make it return to the previous page if i click the back button in the browser? Here's my code below.</p>
  
  <blockquote>
    <p>TS</p>
  </blockquote>
  
  <pre><code>     config: any; 
  
       constructor() {
          this.config = {
                  currentPage: 1,
                  itemsPerPage: 2
              };
  
           this.route.paramMap
              .map(params =&gt; params.get('page'))
              .subscribe(page =&gt; this.config.currentPage = page);
              }
        }
  
        ngOnInit() {
              this.getAllBooks();
  
  
        }
  
        pageChange(newPage: number) {
             this.router.navigate(['/books'], { queryParams: { page: newPage } });
    }
  
          getAllBooks() {
              this.subscription = this.booksService.getAll()
              .subscribe(
                  (data:any) =&gt; {
                      this.books = data;
                  console.log(data);
              },
              error =&gt; {
                  console.log(error);
              });
          }
  </code></pre>
  
  <blockquote>
    <p>HTML</p>
  </blockquote>
  
  <pre><code>&lt;tbody&gt;
            &lt;tr *ngFor="let book of books | paginate: { itemsPerPage: config.itemsPerPage, currentPage: config.currentPage }"&gt;
              &lt;td&gt;{{ book.SKU }}&lt;/td&gt;
              &lt;td&gt;{{ book.name }}&lt;/td&gt;
              &lt;td&gt;{{ book.description }}&lt;/td&gt;
           &lt;/tr&gt;
          &lt;/tbody&gt;
          &lt;/table&gt;
          &lt;pagination-controls (pageChange)=“pageChange($event)” class="my-pagination"&gt;&lt;/pagination-controls&gt;
  </code></pre>