I have a URL like for example 'localhost:3000/verify/a5d5sd', that I have sent to a user's email, upon clicking this link, I am using the param (a5d5sd) in the link for checking some stuff in the server and database(MongoDB) and returning a response with an object, now when the link is clicked or opened on a new tab, I only see the response from the server but not with the HTML from my Angular 2 component.
In my Angular 2 route config module, I did config a route like
{
path: 'verify/:id',
component: MyComponent
},
And on ngOnInit of this component, I am calling a service method that makes a GET http request with a URL like verify/:id the param(:id) I get it using the ActivatedRoute from the @angular/router so that I can make the request.
To handle this I was advised to have the following code for my express to use:
app.use(express.static(path.join(__dirname, 'client/dist')));
app.get('*', function(req, res) {
res.sendFile(__dirname + '/client/dist/index.html');
})
Have even tried with:
app.all('*', function(req, res) {
res.sendFile(__dirname + '/client/dist/index.html');
})
This code works for direct navigation(pasting URLon the search bar) and refreshes for only POST and PUT requests but not working with GET requestS that expects a response from the server side, when I directly visit a URL or refresh the page, the DOM is written with the server response but with not HTML, any assistance will be appreciated.