当我将代码链接放入 Mobx 商店 ( const len
) 时,我立即收到 React 路由错误。例如:
import React, { Component } from "react";
import { observer, inject } from 'mobx-react';
@inject('store') @observer class App extends Component {
render() {
const len = store.goods.length
return (
<div>
<h1>App is there</h1>
<fieldset>
<legend>Done</legend>
{ len }
</fieldset>
</div>
);
}
}
如果我删除它(store.goods.lenght),它可以工作,如果它在那里,我无法到达任何路线。它向我暴露了以下错误:
The above error occurred in the <App> component:
in App (created by inject-App-with-store)
in inject-App-with-store (created by Route)
in Route (created by View)
in Provider (created by View)
in View
in Router (created by BrowserRouter)
in BrowserRouter
<Provider/>
这里取自 mobx。
更新
@withRouter
在声明之前添加装饰器后App class
,控制台中的错误消失了。但这并没有解决问题,因为现在它只是无法显示路线,例如:
Cannot GET /notes
有没有人遇到过这样的案例?