我有一个应用程序,它使用 react-router-config 并使用包装器组件来重定向未经身份验证的用户。
我有一些功能需要使用路由 /tasks/:id 但我无法访问 :id 值来执行必要的任务查找。
我的路线.js:
import React from "react";
...
const Tasks = React.lazy(() => import("./Components/Tasks"));
...
const routes = [
{
path: "/tasks/edit/:id",
name: "View Task",
component: Tasks
}
...
];
export default routes;
Run Code Online (Sandbox Code Playgroud)
然后我有AuthenticatedRoute.js:
import React from "react";
import { Route, Redirect } from "react-router-dom";
export default function AuthenticatedRoute({
component: C,
appProps,
...rest
}) {
return (
<Route
{...rest}
render={props =>
appProps.isAuthenticated ? (
<C {...props} {...appProps} />
) : …Run Code Online (Sandbox Code Playgroud)