koajs/react-view

when I use koa2, the error occurs

jiangtao opened this issue · 0 comments

I use babel6 and babel-register in koa2, some error occours like:

CLI Error:

{ [SyntaxError: /Users/huangjiangtao/Places/Code/Hex/koa-test/views/pages/index.jsx: Unexpected token (16:3)]
  pos: 319,
  loc: Position { line: 16, column: 3 },
  _babel: true,
  codeFrame: '\u001b[0m  14 | \t\t\u001b[90m// xss!!!\u001b[39m\n  15 | \t\t\u001b[36mreturn\u001b[39m \u001b[34m\u001b[1m(\u001b[22m\u001b[39m\n> 16 | \t\t\t\u001b[1m<\u001b[22mLayout title\u001b[1m=\u001b[22m\u001b[32m{\u001b[39m\u001b[36mthis\u001b[39m\u001b[1m.\u001b[22mprops\u001b[1m.\u001b[22mtitle\u001b[32m}\u001b[39m\u001b[1m>\u001b[22m\n     | \t\t\t^\n  17 | \t\t\t\t\u001b[1m<\u001b[22mh1\u001b[1m>\u001b[22m\u001b[32m{\u001b[39m\u001b[36mthis\u001b[39m\u001b[1m.\u001b[22mprops\u001b[1m.\u001b[22mtitle\u001b[32m}\u001b[39m\u001b[1m<\u001b[22m\u001b[1m/\u001b[22mh1\u001b[1m>\u001b[22m\n  18 | \t\t\t\u001b[1m<\u001b[22m\u001b[1m/\u001b[22mLayout\u001b[1m>\u001b[22m\n  19 | \t\t\u001b[34m\u001b[1m)\u001b[22m\u001b[39m\u001b[0m',
  code: 'REACT' }

app.js

const viewpath = path.join(__dirname, 'views');
const assetspath = path.join(__dirname, 'public');
const register = require('babel-register');
react(app, { views: viewpath });

register({
    extensions: [".jsx"]
});

index.jsx

var React = require('react');
var Layout = require('../layouts/main');


module.exports = React.createClass({
    propTypes: {
        title: React.PropTypes.string,
        subtitle: React.PropTypes.string
    },

    render: function() {
        // pass data to client side js
        // xss!!!
        return (
            <Layout title={this.props.title}>
                <h1>{this.props.title}</h1>
            </Layout>
        )
    }
});