gpt4 book ai didi

javascript - React Router 渲染空 div

转载 作者:搜寻专家 更新时间:2023-11-01 00:40:38 24 4
gpt4 key购买 nike

app div 是空的。它里面唯一的东西是一个 noscript 标签。

var React = require('react');
var ReactDOM = require('react-dom');
var reactRouter = require('react-router');

var Router = reactRouter.Router;
var DefaultRoute = reactRouter.DefaultRoute;
var Route = reactRouter.Route;
var RouteHandler = reactRouter.RouteHandler;
var Link = reactRouter.Link;

var LoginHandler = require('./components/LoginHandler.jsx');

var AppComponent = React.createClass({
render: function() {
return(
<nav>
<Link to="/">Home</Link>
<Link to="login">Login</Link>
<RouteHandler/>
</nav>
)
}
});

var routes = (
<Route name="app" path="/" handler={AppComponent}></Route>
)

ReactDOM.render(<Router routes={routes}/>, document.getElementById('app'));`

最佳答案

尝试用 Route 标记中的组件替换处理程序:

var React = require('react');
var ReactDOM = require('react-dom');
var reactRouter = require('react-router');

var Router = reactRouter.Router;
var DefaultRoute = reactRouter.DefaultRoute;
var Route = reactRouter.Route;
var RouteHandler = reactRouter.RouteHandler;
var Link = reactRouter.Link;

var LoginHandler = require('./components/LoginHandler.jsx');

var AppComponent = React.createClass({
render: function() {
return(
<nav>
<Link to="/">Home</Link>
<Link to="login">Login</Link>
<RouteHandler/>
</nav>
)
}
});

var routes = (
<Route name="app" path="/" component={AppComponent}></Route>
)

ReactDOM.render(<Router routes={routes}/>, document.getElementById('app'));

关于javascript - React Router 渲染空 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35713909/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com