我在用路径参数导航react路由器时遇到问题
这是我的设置
render() {
return (
<Switch>
<Route path={Routes.PASSWORD_RECOVERY} component={ForgotPasswordView}/>
<Route path={Routes.VERIFY_EMAIL} component={VerifyEmailView}/>
<Route path={Routes.LOGIN} component={LoginView}/>
<Route path={Routes.SIGN_UP} component={SignUpView}/>
<Route path={Routes.VERIFY_RESULTS} component={VerifyGames}/>
<Route path={Routes.HOME} component={Home}/>
<Route path={Routes.WELCOME} component={Welcome}/>
<Route exact path={Routes.DEFAULT} component={DefaultHome}/>
<Route component={DefaultHome}/>
</Switch>
);
}
这是我的路由
static readonly SIGN_UP = "/signup";
static readonly LOGIN = "/login";
static readonly PASSWORD_RECOVERY = "/password_recovery";
static readonly VERIFY_EMAIL = "/verify_email";
static readonly HOME = "/home";
static readonly WELCOME = "/welcome";
static readonly VERIFY_RESULTS = "/verifier";
static readonly DEFAULT = "/";
现在,我希望能够导航到路由路径/verifier
上的Verify games组件。
如果我只导航到/verifier
,它工作,但如果我附加路径参数,它不能导航。
所以,/verifer
工作,但/verifier?name=mekings&&age=25
失败,总是重路由回DefaultHome组件
为什么?
您是否尝试过将úse组件作为子组件而不是组件prop?
,
<Switch>
<Route path={Routes.SIGN_UP}>
<Login view/>
</Route>
</Switch>
Please share your code on code sandbox if you still have issues.