I have my angular app running inside docker that exposed on port 83, and I also have a spring-boot rest app inside another docker that exposed on port 8083.
In the host server I have one Nginx server that reroute every requests using below config:
server {
listen 80;
server_name mydomain.com;
location / {
proxy_pass http://127.0.0.1:83;
}
}
server {
listen 80;
server_name rest.mydomain.com;
location / {
proxy_pass http://127.0.0.1:8083;
}
}
With above config, every request that uses mydomain.com will goes to my Angular 6 app, and every request that uses rest.mydomain.com will goes to my spring-boot rest app.
In the index page of my angular, I have a search form which will trigger the Routing module to open a search result page.
My app-routing.module.ts is like below:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HomePgComponent } from './home-pg/home-pg.component';
import { ResultsPgComponent } from './results-pg/results-pg.component';
const routes: Routes = [
{ path: "", component: HomePgComponent },
{ path: "search", component: ResultsPgComponent }
];
@NgModule({
imports: [RouterModule.forRoot(
routes,
{ enableTracing: true }
)],
exports: [
RouterModule
]
})
export class AppRoutingModule { }
export const RoutingComponents = [
HomePgComponent,
ResultsPgComponent
];
And the trigger on my search form is like below:
onSearchBtnClk(el) {
if (el.value.length > 0) {
console.log(">>> SEARCH ARGS = " + el.value);
this.router.navigate(['/search'], { queryParams: { q: el.value }});
this.newArgsEmitter.emit(el.value);
}
}
Everything works well, when I click the search button, my angular will open the search result page and shows the results.
My problem is, whenever I click REFRESH button on the browser, instead of a search page result, it shows 404 page. Why is this happen?
Any advice would be appreciated. Thanks