Skip to content

Commit

Permalink
fix(service/back): avoid populating history on back
Browse files Browse the repository at this point in the history
  • Loading branch information
rbalet committed Nov 5, 2024
1 parent 25526ac commit 46c239a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
with:
node-version: 20
cache: 'npm'
- run: npm i
- run: npm ci
# - name: lint
# run: npm run lint
# - run: npm run build
Expand Down Expand Up @@ -43,7 +43,7 @@ jobs:
with:
node-version: 20
cache: 'npm'
- run: npm i
- run: npm ci
- run: npm run build
- name: release
run: cd dist/ngx-back-button && npx semantic-release --branches main
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-back-button",
"version": "18.2.0",
"version": "18.2.1",
"license": "MIT",
"author": "Raphael Balet",
"maintainers": [
Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-back-button/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-back-button",
"version": "18.2.0",
"version": "18.2.1",
"license": "MIT",
"author": "Raphael Balet",
"maintainers": [
Expand Down
7 changes: 6 additions & 1 deletion projects/ngx-back-button/src/lib/ngx-back-button.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export class NgxBackButtonService {
private _rootUrl!: string // Default Fallback in case we do not have any navigation history
private _fallbackPrefix!: string // Always added in case of a Fallback (Useful when used within other libraries)

private _navigatingBack = false

constructor(
@Inject(NgxBackButtonServiceProvider) _config: NgxBackButtonServiceConfig,

Expand All @@ -23,7 +25,9 @@ export class NgxBackButtonService {
this._router.events
.pipe(filter((e): e is NavigationEnd => e instanceof NavigationEnd))
.subscribe((event) => {
this._history.push(event.urlAfterRedirects)
if (!this._navigatingBack) this._history.push(event.urlAfterRedirects)

this._navigatingBack = false
})
}

Expand All @@ -33,6 +37,7 @@ export class NgxBackButtonService {
* @return Boolean: True === Had an history to go back to
*/
back(fallback?: string): boolean {
this._navigatingBack = true
const record = this._history.pop()

if (this._history.length > 0) {
Expand Down

0 comments on commit 46c239a

Please sign in to comment.