React-router path参数不起作用
react-router path parameter doesn't work
我从0.13升级了react-router。X到1.0,但现在url中的path参数不起作用。我使用webpack-dev-server.
index.jsx
const React = require('react');
const ReactDOM = require('react-dom');
var Projects = require('./components/projects/projectsView').Projects;
var Products = require('./components/products/productsView').Products;
var Customers = require('./components/customers/customersView').Customers;
var CustomerDetail = require('./views/customerDetail').CustomerDetail;
var NavBar = require('./views/navigation').NavBar;
var ReactRouter = require('react-router');
var Router = ReactRouter.Router;
var Route = ReactRouter.Route;
var DefaultRoute = ReactRouter.DefaultRoute;
var RouteHandler = ReactRouter.RouteHandler;
var Link = ReactRouter.Link;
var IndexRoute = ReactRouter.IndexRoute;
var History = ReactRouter.History;
var createBrowserHistory = require('../../node_modules/react-router/node_modules/history/lib/createBrowserHistory');
class App extends React.Component {
constructor(props) {
super(props);
}
render () {
return (
<div>
<NavBar />
{this.props.children}
</div>
);
}
}
class Index extends React.Component{
constructor(props) {
super(props);
}
render() {
return (
<div>
<h2> Welcome </h2>
</div>
);
}
}
// declare our routes and their hierarchy
let routes = (
<Route path="/" component={App}>
<IndexRoute component={Index} />
<Route path="products" component={Products} />
<Route path="projects" component={Projects} />
<Route path="customers" component={Customers} />
<Route path="/customer/:customerId" component={CustomerDetail} />
</Route>
);
ReactDOM.render(<Router routes={routes} history={createBrowserHistory()} />, document.getElementById('content'));
在组件产品、项目和客户中创建链接:
<Link to={`/customerDetail/${that.props.customerIdProp}`} >{that.props.customerIdProp}</Link>
当我打开应用程序时,链接被正确呈现:
http://localhost:8080/customerDetail/123
http://localhost:8080/customerDetail/124
http://localhost:8080/customerDetail/125
当我打开a链接时,CustomerDetail组件不呈现,只有空体
<body>
<pre style="word-wrap: break-word; white-space: pre-wrap;"></pre>
</body>
历史是它自己的模块,使用https://www.npmjs.com/package/history代替你的createBrowserHistory要求。
至于你的路由和链接——它们看起来不错,除了你在路由中有/customer/
和链接中有/customerDetail/
。
相关文章:
- setTimeout刷新,毫秒参数不起作用
- 角度限制过滤器's的第二参数“s”;“开始”;在Angular 1.3中似乎不起作用
- 参数使用AJAX的PHP POST不起作用
- UI 路由器参数 URL 不起作用,只是重定向到 /
- JavaScript参数对象不起作用
- 筛选器's的第二个参数不起作用
- 使用输入名称参数在jQuery中取整不起作用
- 在Angular Directive中传递函数作为参数不会;不起作用
- 如果我移除animateTo参数,.remove()回调函数将不起作用
- .eq()参数在循环中不起作用
- 谷歌地图API v3-缩放参数don'不起作用
- UIWebView调用带有参数的JS获胜'不起作用
- JavaScript - 在函数内连接 2 个参数不起作用
- 参数在使用 Google Apps 脚本的 Google 云打印中不起作用
- 参数在 $() - jQuery 之外不起作用
- 为什么传入的参数在一个地方有效,而在另一个地方不起作用
- jQuery 参数不起作用
- 函数在将参数传递给 addEventListener 时不起作用
- angularjs路由不起作用参数'CatCtrl'不是函数,未定义
- Javascript ADO 记录集打开方法不起作用.参数化查询