Skip to content

Commit

Permalink
ci: replace only next or v.x subpath of route (#2691)
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode authored Sep 13, 2022
1 parent c42bb47 commit 7dfc227
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
17 changes: 7 additions & 10 deletions projects/demo/src/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
<meta charset="utf-8" />
<title>Taiga UI</title>
<script>
if (!localStorage.getItem('env')) {
const base = location.pathname + location.search + location.hash;
const segments = base.split('/').filter(Boolean);
const version = segments[0] ?? ``;
const pattern = /^(next|v[0-9])$/;
const base = `${location.pathname}${location.search}${location.hash}`;
const segments = base.split('/').filter(Boolean);
const version = segments[0] ?? ``;
const pattern = /^(next|v[0-9])$/;
const redirectUrl = pattern.test(version) ? `/${version}` : `/`;

localStorage.setItem('env', base);
location.replace(pattern.test(version) ? `/${version}` : `/`);
} else {
localStorage.removeItem('env');
}
localStorage.setItem('env', base);
location.replace(redirectUrl);
</script>
</head>
<body></body>
Expand Down
2 changes: 1 addition & 1 deletion projects/demo/src/modules/app/abstract.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export abstract class AbstractDemoComponent implements OnInit {

if (env) {
this.storage.removeItem(`env`);
await this.router.navigateByUrl(env.replace(/\/[A-z0-9]*\//, ``));
await this.router.navigateByUrl(env.replace(/^\/(next|v[0-9])\//, ``));
}
}
}

0 comments on commit 7dfc227

Please sign in to comment.