使用历史模块 1.13.1 配置后,React-router 1.0.2 不工作
React-router 1.0.2 is not working after configure with History module 1.13.1
使用示例应用程序 here 配置 history
模块后,我遇到了这个问题。
我尝试在 react-router 文档 Navigating Outside of Components 中遵循这种模式,并在
中实现了它
import createBrowserHistory from 'history/lib/createBrowserHistory';
export default createBrowserHistory();
配置 router
import React from 'react';
import {render} from 'react-dom';
import { Router, Route, Link, IndexRoute } from 'react-router';
import createHistory from 'history/lib/createBrowserHistory';
import history from './config/history';
import routes from './config/routes';
let el = document.getElementById('login');
render(<Router history={history}>{routes}</Router>, el);
正在尝试使用 here
import history from '../config/history';
我正在使用 webpack,您可以使用 npm run webpack
构建它,然后使用 python -m SimpleHTTPServer 8080
构建服务器文件。
在那之后,当我想去 http://localhost:8080/public/login.html#/setup
时,它给出了以下错误。
Warning: Location "/public/login.html#/setup?_k=rnwzln" did not match any routes
如果我在 Login.js
中删除 history={history}
,它会完美地工作
你能帮我解决这个问题吗?是 react-router 的 bug 吗?
P.S.: 我已经调查过这个 Whosebug question,但它没有解决我的问题。
您正在使用 browserHistory 并期望哈希 url 匹配。
https://github.com/rackt/react-router/blob/1.0.x/docs/guides/basics/Histories.md
使用示例应用程序 here 配置 history
模块后,我遇到了这个问题。
我尝试在 react-router 文档 Navigating Outside of Components 中遵循这种模式,并在
中实现了它import createBrowserHistory from 'history/lib/createBrowserHistory';
export default createBrowserHistory();
配置 router
import React from 'react';
import {render} from 'react-dom';
import { Router, Route, Link, IndexRoute } from 'react-router';
import createHistory from 'history/lib/createBrowserHistory';
import history from './config/history';
import routes from './config/routes';
let el = document.getElementById('login');
render(<Router history={history}>{routes}</Router>, el);
正在尝试使用 here
import history from '../config/history';
我正在使用 webpack,您可以使用 npm run webpack
构建它,然后使用 python -m SimpleHTTPServer 8080
构建服务器文件。
在那之后,当我想去 http://localhost:8080/public/login.html#/setup
时,它给出了以下错误。
Warning: Location "/public/login.html#/setup?_k=rnwzln" did not match any routes
如果我在 Login.js
中删除 history={history}
,它会完美地工作
你能帮我解决这个问题吗?是 react-router 的 bug 吗?
P.S.: 我已经调查过这个 Whosebug question,但它没有解决我的问题。
您正在使用 browserHistory 并期望哈希 url 匹配。
https://github.com/rackt/react-router/blob/1.0.x/docs/guides/basics/Histories.md