我得到标题上指出的错误,而且我不确定如何摆脱它并使我的应用正常运行。
我一直在尝试解决它,但是还找不到解决方案。我发现与错误有关的唯一内容是此注释:“您不能在React Native中使用文档,您可以在菜单后面创建一个背景,然后在按背景时将其隐藏。” Fayeed撰写。尽管这似乎是我的答案,但我不确定如何创建该背景。这是我的代码:
import React from 'react';
import ReactDOM from 'react-dom';
import {Route, Link, BrowserRouter as Router} from 'react-router-dom';
import news from './components/News';
import eating from './components/Eating';
import LoginForm from './components/LoginForm';
import ApolloClient from 'apollo-client';
import {ApolloProvider} from 'react-apollo';
import {HttpLink} from 'apollo-link-http';
import {InMemoryCache} from 'apollo-cache-inmemory';
const client= new ApolloClient({
link: new HttpLink({uri:'https://api-useast.graphcms.com/v1/ck25kwqhb10bg01cx4o1i5czu/master'}),
cache:new InMemoryCache()
})
const routing = (
<Router>
<Route path="/" component={LoginForm} />
<Route path="/news" component={News} />
<Route path="/eating" component={Eating} />
</Router>
)
ReactDOM.render((
<ApolloProvider client={client}>
routing
</ApolloProvider>
),
document.getElementById('root')
)
这是我的package.json文件:
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"apollo-cache-inmemory": "^1.6.3",
"apollo-client": "^2.6.4",
"apollo-link-http": "^1.5.16",
"expo": "^35.0.0",
"graphql": "^14.5.8",
"react": "16.8.3",
"react-apollo": "^3.1.3",
"react-dom": "^16.8.3",
"react-native": "https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz",
"react-native-web": "^0.11.7",
"react-router-dom": "^5.1.2"
},
"devDependencies": {
"babel-preset-expo": "^7.1.0"
},
"private": true
}
我希望能够加载我的应用程序而不会出现任何错误。
答案 0 :(得分:0)
我解决了它,我必须下载react-router-native而不是react-router-DOM。就是这样代替:
import React from 'react';
import ReactDOM from 'react-dom';
import {Route, Link, BrowserRouter as Router} from 'react-router-dom';
mport ApolloClient from 'apollo-client';
import {ApolloProvider} from 'react-apollo';
import {HttpLink} from 'apollo-link-http';
import {InMemoryCache} from 'apollo-cache-inmemory';
我必须做:
import React, {Component} from 'react';
import {Route, Link, NativeRouter as Router} from 'react-router-native';
import ApolloClient from 'apollo-client';
import {ApolloProvider} from 'react-apollo';
import {HttpLink} from 'apollo-link-http';
import {InMemoryCache} from 'apollo-cache-inmemory';
并将该DOM渲染替换为类组件。