我对propTypes有疑问。如果查看LoginLayoutRoute.propTypes,我如何验证组件是否正在传递。
const LoginLayoutRoute = ({ component: Component, ...rest }) => (
<Route
{...rest}
render={matchProps => (
<LoginLayout>
<Component {...matchProps} />
</LoginLayout>
)}
/>
)
LoginLayoutRoute.propTypes = {
component: ...,
}
const RouterSetup = () => (
<Router>
<Switch>
<LoginLayoutRoute path="/login" component={LoginPage} />
</Switch>
</Router>
)
答案 0 :(得分:0)
我能够弄清楚。它看起来像这样:
------- beginning of crash
05-28 20:52:04.514 19691-19691/com.wube.wubealpha E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.wube.wubealpha, PID: 19691
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.wube.wubealpha/com.wube.wubealpha.MainActivity}: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.get(ArrayList.java:411)
at com.wube.wubealpha.MainActivity.onCreate(MainActivity.java:64)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)