0

I have a view, that actually is rendering only after an axios request finish, but I need to render the view first, and when the request is ready, I pass the parameter to the view.

Actually:

app.get('/', function(req, res){
axios.get('example.com')
.then(function(response) {
res.render('routes/site/index', {ctx: response});
});
});

What I need:

The view loading before the request, and after the request ready, only pass the parameter to the same view that was already loaded.

Kloves
  • 119
  • 1
  • 7

2 Answers2

0

You cannot do res.render() twice for 1 request.

I suggest you render your page without a parameter, do the axios/fetch request client side, and when the request is done handle the response like you would do.

Hobey823
  • 276
  • 4
  • 13
0

You can't send parameters after using res.render().

However, what you can do is use a javascript code asking for the parameter on the client side. (Inside your index page here)

Here's an example of how to do that: http get in javascript