I have a Angular4 application and when the backend server goes down i want it to redirect to a error page. Im using this solution to check wheter the server is down. But how can i route to a static error page from here? I cant use router here becaus then ill get cyclic dependency error.
Asked
Active
Viewed 191 times
1
-
Can you show how you are using `router` when cyclic dependency error is triggered? – asimhashmi May 15 '19 at 11:52
-
as the link you references advises: use the HttpInterceptor. Then you can use the router to redirect – Marcel Hoekstra May 15 '19 at 11:53
-
@MarcelHoekstra If i do that then there wil be few request that it will not cover. I hae few requests that are made using Http instead of HttpClient, and it seems Http and Router cannot be refrenced from same class. How can i use router from a class that imports or exctends Http ? – Marko Taht May 15 '19 at 12:05
-
@AsimHashmi i just have router inside the constructor parameter list. Thats it. – Marko Taht May 15 '19 at 12:11
-
If it's just redirect you can always use simple `window.location.href` or `window.location.open(...)` – Marcin Tomczyk May 15 '19 at 12:25
-
@MarcinTomczyk yes that worked. I just have to place my error page as static content. Only issue i have is the url: assets/errorPage/errorPage.html. Is there a way to make this more nice ? – Marko Taht May 15 '19 at 12:59
-
@MarkoTaht Yes, look into `angular.json` and use build assets options. You can copy files by name or use object with glob, input and output options to change how static assets are emmited – Marcin Tomczyk May 15 '19 at 13:06