无法获取用户 ID 路由参数以在反应路由器中继上工作
Can't get userID route parameter to work on react-router-relay
我正在尝试使用 react-relay-router 学习 React Relay 和 GraphQL,但无法在我的路由中获取参数来工作。我的困难在于"/Maps/:userID"路线。
这是我的路由器:
ReactDOM.render(
<RelayRouter history={browserHistory}>
<Route path="/"
component={HomeSubAppContainer}
renderLoading={() => <Spinner/>}
>
<IndexRoute component={WelcomePageContainer}/>
</Route>
<Route path="/Maps/:userID"
component={MapsSubAppContainer}
renderLoading={() => <Spinner/>}
queries={userRootQuery}
>
<IndexRoute
component={WeekMapContainer}
renderLoading={() => <Spinner/>}
/>
</Route>
</RelayRouter>,
document.getElementById('root')
);
这是我的中继容器和根查询:
export const MapsSubAppContainer = Relay.createContainer(MapsSubApp, {
fragments: {
user: () => Relay.QL
` fragment on User {
birthDate
}
`
}
});
export const userRootQuery = {
user: () => Relay.QL
` query {
user(userID: $userID)
}
`
};
这是我的反应组件中我在路由参数中插入用户 ID 的位置。我正在使用来自反应路由器的浏览器历史记录。"1"是我的测试用户 ID。
handleSubAppsNavClick(button) {
const path = button === 'Maps' ? '/Maps/1' : '/' + button;
browserHistory.push(path);
}
这是我的架构的根查询:
var queryType = new GraphQLObjectType({
name: 'Query',
fields: () => ({
node: nodeField,
user: {
type: userType,
args: {
userID: {type: GraphQLString}
},
resolve: (args) => getUser(args.userID)
}
})
});
我尝试按照反应路由器中继 Github 页面上的示例代码进行操作,但出现控制台错误:
警告:[反应路由器]位置"/地图"与任何路由都不匹配
感谢您提供的任何建议。
您的代码中有某种错误,使其尝试导航到 /Maps
,您没有为此设置路由。仔细检查您如何进行过渡。
我正在将userID添加到MapsSubApp组件中的路由中,但是在路由器转到Maps/userID之前,我应该在早期的HomeSubApp组件中执行此操作。
相关文章:
- AngularJS UI路由器不能像ng路由器那样工作
- 流星铁路由器动态段不工作
- 当名称空间在id参数之前声明时,Angular UI路由器停止工作
- angular ui路由器不工作
- 无法获取用户 ID 路由参数以在反应路由器中继上工作
- ExpressJS路由器不工作
- 铁:路由器工作很奇怪 - 将我发送到模板然后返回
- Angular (1.5.0) ng 路由器不工作
- ng-controller工作,UI路由器:控制器不是
- UI 路由器不加载 rawgit 中的视图,但在本地工作
- 如何在Microsoft IIS上使用反应路由器(createBrowserHistory)使路由工作
- React路由器不工作
- angular ui路由器状态模板不工作
- 使用react路由器,redux将无法工作
- 具有url参数的角度状态/路由器不工作
- 为什么angularjs路由器在这里不工作
- Angular UI路由器工作不正常
- 骨干路由器是'工作不正常
- 无法让UI路由器在我的Angular Framework中工作
- 我的主干js路由器是't工作