2016-06-20 60 views
0

我剛開始學習ReactJS,我似乎無法讓onClick處理程序正常工作。ReactJS + Express.js + React-Bootstrap:引導按鈕不起作用的onClick處理程序

我遵循了Express.js應用程序生成器教程,並以下面的代碼結束。

有人可以告訴我有什麼問題嗎?

//app.js file 
 

 
var express = require('express'); 
 
var path = require('path'); 
 

 
// routes 
 
var launch = require('./routes/launch'); 
 

 
var app = express(); 
 

 
// view engine setup 
 
app.set('views', __dirname + '/views'); 
 
app.set('view engine', 'jsx'); 
 
app.engine('jsx', require('express-react-views').createEngine()); 
 

 
app.use(bodyParser.json()); 
 
app.use(bodyParser.urlencoded({ extended: false })); 
 
app.use(cookieParser()); 
 
app.use(express.static(path.join(__dirname, 'public'))); 
 

 
// attach url to routes 
 
app.use('/', launch);

//launch.js 
 

 
var express = require('express'); 
 
var router = express.Router(); 
 

 

 
router.get('/', function(req, res, next) { 
 
    res.render('launch', {}); 
 
}); 
 

 
module.exports = router;

//launch.jsx code 
 

 
var React = require('react'); 
 
var DefaultLayout = require('./layouts/default'); 
 

 
// bootstrap 
 
import {Button, Grid, Row, Col, Clearfix, Image, FormGroup, InputGroup, FormControl} from 'react-bootstrap'; 
 

 
var LaunchView = React.createClass({ 
 
    render: function() { 
 
    return (
 
     <FormGroup> 
 
     <InputGroup> 
 
     <FormControl id="launch-email" type="email" placeholder="Email" /> 
 
     <InputGroup.Button> 
 
     <Button id="launch-submit" className="button-green" onClick={this.handleSubmit}>Submit</Button> 
 
     </InputGroup.Button> 
 
     </InputGroup> 
 
     </FormGroup> 
 
    ); 
 
    }, 
 
    handleSubmit: function(){ 
 
    alert("woot"); 
 
    } 
 
}); 
 

 
module.exports = LaunchView;

+0

https://codepen.io/erichardson30/pen/aZmQBm這對我來說很好。你有什麼問題? – erichardson30

+0

@ erichardson30我沒有使用React.render();. ExpressJs使用路線。我剛剛在我的問題中添加了路線文件。 –

+0

當您導航到路線時,組件是否呈現? – erichardson30

回答