小编Ben*_* Li的帖子

在react-router-dom V6中重定向

登录后我需要导航回原始请求的 URL。

例如,用户输入www.example.com/settings时未经过身份验证,它将导航到登录页面www.example.com/login

一旦通过身份验证,它应该自动导航回www.example.com/settings

我最初使用react-router-domv5 的方法非常简单:

const PrivateRoute = ({ isLoggedIn, component: Component, ...rest }) => {
  return (
    <Route
      {...rest}
      render={(props) =>
        isLoggedIn? (
          <Component {...props} />
        ) : (
          <Redirect
            to={{ pathname: `/login/${props.location.search}`, state: { from: props.location } }}
          />
        )
      }
    />
  );
};


<PrivateRoute exact isLoggedIn={isLoggedIn} path="/settings" component={Settings} />

Run Code Online (Sandbox Code Playgroud)

有人可以告诉我如何在 v6 中做到这一点吗?提前致谢

javascript reactjs react-router-dom

14
推荐指数
1
解决办法
2万
查看次数

将父窗口的 css 变量应用到 iframe

我有一个父窗口和一个 iframe。

在父窗口中html,我有一个 CSS 变量列表:

:root {
  --lp-font-size-heading-lg: 2.5rem;
  --lp-font-size-heading-md: 2rem;
  --lp-font-size-heading-sm: 1.5rem;
}    
Run Code Online (Sandbox Code Playgroud)

但这些变量在 iframe 中不可用,即在 iframe 的标头中,我有:

font-size: var(--lp-font-size-heading-md);
Run Code Online (Sandbox Code Playgroud)

但 iframe 找不到的定义--lp-font-size-heading-md

如何在iframe中添加CSS变量?

html javascript css iframe

6
推荐指数
1
解决办法
701
查看次数

标签 统计

javascript ×2

css ×1

html ×1

iframe ×1

react-router-dom ×1

reactjs ×1