我正在编写一个React + Redux + ReactNative应用程序,它为多个平台( Web、IOS、Android)共享相同的代码。
所以 UI 组件是不同的,但是模型和逻辑在平台之间是共享的。
当我试图导航到一个不同的页面时,我遇到了一个问题,在一个动作中,例如:(我正在使用 react-router 和 react-native-router-flux)
import {browserHistory} from "react-router";
import {Actions} from 'react-native-router-flux'; // This is the problematic import
export function signInSuccessAndRoute(user) {
if (PlatformInfoShared.isWeb()) {
const path = '/dashboard';
browserHistory.push(path);
} else {
Actions.mainApplication();
}
return signInSuccess(user);
}
问题是,在网上我收到了这个错误:
index.js:1Uncaught SyntaxError:意外的令牌导入
我正在寻找一种作为 If 语句导入的方法,这意味着仅当平台是移动/Web 时才导入,这怎么可能?
或者您可能想到的任何其他选择...谢谢