Skip to content

Commit

Permalink
feat(docs): routing in production (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
Margar1ta authored and pimenovoleg committed Sep 27, 2019
1 parent 609dc08 commit cdeca45
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
20 changes: 20 additions & 0 deletions 404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<script>
const serverSlash = 5;
const route = location.href.split("/");
route.splice(0,serverSlash);
const path = `${location.href.split("/").slice(0,serverSlash).join("/")}${location.search? location.search + '&' : '?'}nextRoute=${route}`;
location.href = path;
</script>
</head>

<body>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';


@Component({
Expand All @@ -8,10 +8,41 @@ import { Router } from '@angular/router';
})
export class MainLayoutComponent {

constructor(private router: Router) {
constructor(private router: Router,
private route: ActivatedRoute) {

this.setNextRoute();

if (this.router.routerState.snapshot.url === '/') {
this.router.navigateByUrl('button/overview');
}
}

setNextRoute() {
const search = this.getParams();
if (!search || !search.nextRoute) { return; }
const nextRoute = search.nextRoute;
delete search.nextRoute;
const route = nextRoute + this.setParams(search) + location.hash;
this.router.navigateByUrl(route.split(',').join('/'));
}

getParams() {
const search = location.search.substring(1);

if (search) {
return JSON.parse(`{"${decodeURI(search).replace(/"/g, '\\"')
.replace(/&/g, '","')
.replace(/=/g, '":"')}"}`);
}
}

setParams(search) {
if (Object.keys(search).length) {
return `?${JSON.stringify(search).replace(/","/g, '&').replace(/":"/g, '=').slice(2,-2)}`;
}

return '';
}

}

0 comments on commit cdeca45

Please sign in to comment.