gpt4 book ai didi

javascript - react 路由器:位置 "/"与任何路由都不匹配

转载 作者:行者123 更新时间:2023-11-29 16:45:39 24 4
gpt4 key购买 nike

这是我的代码

import React from 'react';
import { Router, Route, IndexRoute, hashHistory } from 'react-router';

import Home from './components/Home';
import ArtistMain from './components/artists/ArtistMain';


const componentRoutes = {
component: Home,
path: "/",
indexRoute: { component: ArtistMain },
childRoutes: [
{
path: "artists/new",
getComponent(location, cb) {
System.import('./components/artists/ArtistCreate')
.then(module => cb(null, module.default));
}
},
{
path: "artists/:id",
getComponent(location, cb) {
System.import('./components/artists/ArtistDetail')
.then(module => cb(null, module.default));
}
},
{
path: "artists/:id/edit",
getComponent(location, cb) {
System.import('./components/artists/ArtistEdit')
.then(module => cb(null, module.default));
}
}
]
};

const Routes = () => {
return (
<Router history={hashHistory} router={componentRoutes} />
);
};

export default Routes;

在浏览器中运行时,我在 javascript 控制台中看到一个空白页面和以下示例:

Warning: [react-router] Location "/" did not match any routes

这些是我的依赖项:

"dependencies": {
"faker": "^3.1.0",
"lodash": "^4.17.2",
"react": "^15.4.1",
"react-dom": "^15.4.1",
"react-input-range": "^0.9.2",
"react-redux": "^4.4.6",
"react-router": "^3.0.0",
"redux": "^3.6.0",
"redux-form": "^6.3.2",
"redux-thunk": "^2.1.0"
},

Why is not a duplicated question: because other SO question was resolved migrating to react-router v3, and I'm already at this version, or importing IndexRoute instead of indexroute or similar, but I've no this typo in my code; also, I've not problem about replacing browserhistory with hashHistory because I'm already using it; also, the 99% of SO question on this topic is using declarative syntax, while i'm using js.

最佳答案

相当肯定这是因为 router 属性应该是 routes:

const Routes = () => {
return (
<Router history={hashHistory} routes={componentRoutes} />
);
};

关于javascript - react 路由器:位置 "/"与任何路由都不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41934766/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com