Reactjs 使用TypeScript在react redux应用程序中以编程方式导航

Reactjs 使用TypeScript在react redux应用程序中以编程方式导航,reactjs,typescript,redux,react-redux,react-router,Reactjs,Typescript,Redux,React Redux,React Router,几个小时以来,我一直没有找到一种方法或任何好的文档可以告诉我如何通过编程导航到任何页面。以下是我的用例: 我有一个登录表单,一旦用户成功登录,他们就应该导航到帐户页面,因此我尝试从我的操作执行此重定向,下面是我的代码(注意:我使用的是typescript): 一种方法是使用react router redux import { push } from 'react-router-redux'; ... dispatch(push(`/account/${user.id}`)); 您的App.t

几个小时以来,我一直没有找到一种方法或任何好的文档可以告诉我如何通过编程导航到任何页面。以下是我的用例: 我有一个登录表单,一旦用户成功登录,他们就应该导航到帐户页面,因此我尝试从我的操作执行此重定向,下面是我的代码(注意:我使用的是typescript):


一种方法是使用
react router redux

import { push } from 'react-router-redux';
...
dispatch(push(`/account/${user.id}`));
您的App.tsx有一个空的
组件,该组件未连接到redux,因为它未嵌套在
标记中

/* App.tsx */
render () {
    const store = createStore(reducers, {}, applyMiddleware(ReduxThunk));

    return (
        <Provider
            store={store}>
            <Router>
                <Switch>
                    <Route exact path="/" component={LoginForm} />
                    {/* <Route exact path="/" component={EmployeeList} /> */}
                    <Route path="/account" component={Account} />
                </Switch>
            </Router>                
        </Provider>
    )
}
/*App.tsx*/
渲染(){
conststore=createStore(reducer,{},applyMiddleware(ReduxThunk));
返回(
{/*  */}
)
}

一种方法是使用
react router redux

import { push } from 'react-router-redux';
...
dispatch(push(`/account/${user.id}`));
您的App.tsx有一个空的
组件,该组件未连接到redux,因为它未嵌套在
标记中

/* App.tsx */
render () {
    const store = createStore(reducers, {}, applyMiddleware(ReduxThunk));

    return (
        <Provider
            store={store}>
            <Router>
                <Switch>
                    <Route exact path="/" component={LoginForm} />
                    {/* <Route exact path="/" component={EmployeeList} /> */}
                    <Route path="/account" component={Account} />
                </Switch>
            </Router>                
        </Provider>
    )
}
/*App.tsx*/
渲染(){
conststore=createStore(reducer,{},applyMiddleware(ReduxThunk));
返回(
{/*  */}
)
}

它什么也没做,我需要对减速器进行任何更改吗?或者别的什么地方?不,确保你的路线是有效的。我提供的是一个我检查过的例子,我正在推有效的路线,但什么都没有发生。它什么都没做,我需要对减速器做任何更改吗?或者别的什么地方?不,确保你的路线是有效的。我提供的是一个我检查过的示例,我正在推有效的路线,但什么都没有发生