react.js - react-router IndexRedirect无效
本文介绍了react.js - react-router IndexRedirect无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
打开路径/,不会跳转到/hot/now路由,indexRedirect的设置没起作用
import React, { Component } from 'react';
import ReactDom from 'react-dom';
import { Router, Route, IndexRoute, IndexRedirect, hashHistory } from 'react-router';
import { Provider } from 'react-redux';
import { syncHistoryWithStore } from 'react-router-redux';
import store from './redux/store';
const history = syncHistoryWithStore(hashHistory, store);
class App extends Component {
render() {
return (
<div>
{this.props.default}
</div>
);
}
}
ReactDom.render(
<Provider store={store}>
<Router history={history}>
<Route path="/" component={App}>
<IndexRedirect to="/hot/now" />
<Route path="p/:id"
getComponent={(location, callback) => {
require.ensure([], require => {
callback(null, require('./widget/article/article'))
}, 'article')
} } />
<Route path=":type/:cate"
getComponent={(location, callback) => {
require.ensure([], require => {
callback(null, require('./widget/trend/trend'))
}, 'trend')
} } />
</Route>
</Router>
</Provider>,
document.getElementById('app')
);
解决方案
是不是前面的尖括号没写对,写成了中文的
这篇关于react.js - react-router IndexRedirect无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文