Hey i am trying to pass two parameters in my url for a simple spa and the params values will be extracted from the url using an api and passed to the server here is the url:
http://localhost:8080/#/game/username/token
but when i am hitting the url its passing this in the network:
Request URL:http://localhost:8080/api/game/usernametoken
and hence it is not hitting the right api
router:
{path:'game/:name/:token', name:'game', component: game }
front end:
this.$http.get('/api/game/'+this.$route.params.name+this.$route.params.token)
server-side:
app.get('/api/game/:name/:token',function(req,res,err){
var tex = {push:false};
console.log("diplaying token from the server"+req.params.name+req.params.token)
res.end(JSON.stringify(tex));
})
To add a parameter to the URL, add a /#/? to the end, followed by the parameter name, an equal sign (=), and the value of the parameter. You can add multiple parameters by including an ampersand (&) between each one.
You can get the query string parameter simply using Vue. js route. In the given URL the key is test and the value is yay .
Using Props To Share Data From Parent To Child # VueJS props are the simplest way to share data between components. Props are custom attributes that we can give to a component. Then, in our template, we can give those attributes values and — BAM — we're passing data from a parent to a child component!
Your get request should be
this.$http.get('/api/game/'+this.$route.params.name + '/' + this.$route.params.token)
You forgot the '/'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With