2017-10-09 94 views
0

我有AA RN的應用程序(RN版本0.48.3),我的文件夾結構:陣營本地導入路徑快捷方式的問題

/index.ios.js 
/index.android.js 
/app/index.js 

index.ios.js:

import {AppRegistry} from 'react-native'; 
import home from './app'; 
AppRegistry.registerComponent('home',() => home); 

/應用/ index.js:

import React, { Component } from 'react'; 
import { 
    AppRegistry, 
    View 
} from 'react-native'; 

export default class home extends Component { 
    render() { 
    return (
     <View> 
    ... 
     </View> 
    ); 
    } 
} 

如果我運行的應用程序,它顯示了我這個錯誤:

Element type is invalid: expected a string (for Built-in components) or a class/Object...

但是,當一個變化index.ios.js第二線是否能夠正常工作:

import home from './app'; -> import home from './app/index.js'; 

任何人都可以向我解釋爲什麼? 「./app」路徑在index.js裏面不正確?

回答

1

嘗試與駝峯主頁,並從你的類名除去家裏

瞧:

import React, { Component } from 'react'; 
import { 
    AppRegistry, 
    View 
} from 'react-native'; 

export default class extends Component { 
    render() { 
    return (
     <View> 
    ... 
     </View> 
    ); 
    } 
} 



import {AppRegistry} from 'react-native'; 
    import Home from './app'; 
    AppRegistry.registerComponent('Home',() => Home); 
+0

同樣的錯誤......,如果我從」 ./app改變與進口首頁路徑才起作用/index.js';它不是一個問題,但我想知道爲什麼... –

+0

我的解決方案工作? 當你把./app放在一個節點上時,你需要使用module.export對象中的annomye元素,在你的情況下你已經指定了一個名字,而導出的默認值不需要名稱,如果你想要做什麼沒有。這裏有一個例子:{Home}和導出類Home ... –

+0

謝謝,但是我對你的解決方案有同樣的錯誤,似乎無法得到路徑「./app」,但只能使用「./app/index。 JS「的工作... –