Answer the question
In order to leave comments, you need to log in
Why does my request display an html page?
I make an axios request, but I get not a response, but html markup, I don’t understand how to fix this error?
Here is my
Home.js implementation
import React, {Component} from 'react';
import { connect } from 'react-redux';
import axios from 'axios';
class Home extends Component{
constructor(props){
super(props);
}
componentWillMount(){
axios.get('/api/test-thema').then(response => console.log(response.data));
}
...
}
const mapStateToProps = state => ({
user: state.login.user
});
export default connect(mapStateToProps)(Home);
router.get('/api/test-thema', async ctx => {
ctx.body = await Test.allThemes(1);
})
let Test = {
allThemes: function(id){
return requestTest('SELECT name FROM thema id_possition = ?', id);
},
...
};
function requestTest(sql, req) {
return new Promise((resolve, reject) => {
db.query(
sql,
[req],
(err, rows) => {
if(err) reject(err);
resolve(rows);
});
});
}
module.exports = Test;
<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"><meta http-equiv="x-ua-compatible" content="ie=edge"><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.4/css/bootstrap.min.css" integrity="2hfp1SzUoho7/TsGGGDaFdsuuDL0LX2hnUp6VkX3CUQ2K4K+xjboZdsXyp4oUHZj" crossorigin="anonymous"><link rel="stylesheet" type="text/css" href="/css/index.css"><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js" integrity="sha384-THPy051/pYDQGanwU6poAc/hOdQxjnOEXzbT+OuUAFqNqFjL+4IGLBgCJC3ZOShY" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.2.0/js/tether.min.js" integrity="sha384-Plbmg8JY28KFelvJVai01l8WyZzrYWG825m+cZ0eDDS1f7d/js6ikvy1+X+guPIB" crossorigin="anonymous"></script><script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.4/js/bootstrap.min.js" integrity="VjEeINv9OSwtWFLAtmc4JCtEJXXBub00gtSnszmspDLCtC0I4z4nqz7rEFbIZLLU" crossorigin="anonymous"></script></head><body><div id="content"></div><script src="/client/bundle.js"></script></body></html>
Answer the question
In order to leave comments, you need to log in
Because the first route always works for you:
.get('*', async ctx => {
await ctx.render('index');
})
.get('/api/logout', async ctx => {
console.log('router');
ctx.logout();
console.log(ctx.state.user);
})
.get('*', async ctx => {
await ctx.render('index');
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question