我读过一些哈巴狗文档.它说我必须先安装哈巴狗,我已经完成了.然后我必须在我的js文件中要求哈巴狗.但我不知道在我的反应文件中编写pug文件的编译位置?在反应框架中使用哈巴狗的正确步骤是什么?谢谢!我真的很感激任何帮助.这是我的反应中的一个组件,我想用哈巴狗渲染它.
import React from 'react';
import Sidebar from './Sidebar';
import Header from './header/Header';
import {tokenverify} from '../../utils/helpers';
import pug from 'pug';
class Home extends React.Component {
componentDidMount() {
const token = localStorage.getItem('token')
tokenverify(token)
.catch((res) => {
this.props.history.push('/')
})
}
render() {
return(
<div className="main-container">
<div className="col-md-1">
<Sidebar history={this.props.history} username={this.props.params.username}/>
</div>
<div className="col-md-11">
<div className="row">
<Header history={this.props.history} username={this.props.params.username} />
</div>
<div className="row">
{this.props.children}
</div>
</div>
</div>
)
}
}
export default Home
Run Code Online (Sandbox Code Playgroud) 我正在使用浏览器历史记录,这是我在routes.js中的代码
export default (
<Router history={browserHistory}>
<Route path="/" component={Main}>
<Route path="home/:username" component={Home}>
<IndexRoute component={HomeContent}></IndexRoute>
<Route path="widget/:second" component={Widget}></Route>
<Route path="email/:second" component={Email}>
<Route path="compose" component={ComposeEmail}></Route>
<IndexRoute component={CheckEmail}></IndexRoute>
</Route>
<Route path="social/:second" component={Social}></Route>
<Route path="calendar/:second" component={Calendar}></Route>
</Route>
<IndexRoute component={Login}></IndexRoute>
</Route>
</Router>
);
Run Code Online (Sandbox Code Playgroud)
我使用this.context.router.push('/')进行导航.我不知道为什么这个警告会一直显示在我的控制台中?
"Warning: [react-router] `Router` no longer defaults the history prop to hash history. Please use the `hashHistory` singleton instead."
Run Code Online (Sandbox Code Playgroud)
我已经阅读了https://github.com/reactjs/react-router/blob/master/upgrade-guides/v2.0.0.md#no-default-history中的文档,但它并没有真正帮助.
我很感激任何帮助:)