为 Cordova 反应条件路由器
React conditional router for Cordova
我正在尝试在 Cordova 中的 React 应用程序的哈希历史记录和浏览器历史记录之间切换。
在 Web 上我想使用浏览器历史记录,在 Cordova 中我必须使用 HashHistory
我试过
import createBrowserHistory from 'history/createBrowserHistory'
import createHashHistory from 'history/createHashHistory'
export default window.cordova ? createHashHistory() : createBrowserHistory()
但没有任何加载。
createHashHistory() works fine.
有没有办法使这个成为条件?
即所以在科尔多瓦它使用哈希历史,如果不是它会使用浏览器历史?
此 hack
突出显示了问题 here
let baseName = document.location.pathname.split('index.html')[0] + 'index.html';
但我不确定如何有条件地实现它。
import React from 'react';
import ReactDOM from 'react-dom';
import createBrowserHistory from 'history/createBrowserHistory'
import createHashHistory from 'history/createHashHistory'
import App from './App'
var history
const startApp = () => {
ReactDOM.render(
<Router history={history} >
<Route component={App} />
</Router>,
document.getElementById('root'));
}
if(!window.cordova) {
history = createBrowserHistory()
startApp()
}
else{
history = createHashHistory()
document.addEventListener('deviceready', startApp, false)
}
我正在尝试在 Cordova 中的 React 应用程序的哈希历史记录和浏览器历史记录之间切换。
在 Web 上我想使用浏览器历史记录,在 Cordova 中我必须使用 HashHistory
我试过
import createBrowserHistory from 'history/createBrowserHistory'
import createHashHistory from 'history/createHashHistory'
export default window.cordova ? createHashHistory() : createBrowserHistory()
但没有任何加载。
createHashHistory() works fine.
有没有办法使这个成为条件?
即所以在科尔多瓦它使用哈希历史,如果不是它会使用浏览器历史?
此 hack
突出显示了问题 here let baseName = document.location.pathname.split('index.html')[0] + 'index.html';
但我不确定如何有条件地实现它。
import React from 'react';
import ReactDOM from 'react-dom';
import createBrowserHistory from 'history/createBrowserHistory'
import createHashHistory from 'history/createHashHistory'
import App from './App'
var history
const startApp = () => {
ReactDOM.render(
<Router history={history} >
<Route component={App} />
</Router>,
document.getElementById('root'));
}
if(!window.cordova) {
history = createBrowserHistory()
startApp()
}
else{
history = createHashHistory()
document.addEventListener('deviceready', startApp, false)
}