这是我要实现的目标:当用户尝试访问我的ReactJS网站上的受保护页面时,我想通过一条简短的消息“请登录”或类似内容将其重定向到首页。我如何使用react-router v4实现此目的。这是我到目前为止的内容:
<Router>
<div>
<Switch>
<Route path="/" component={Home} />
<Route
exact path="/source" render={() => (
isAuthenticated() ? (
<Source />
) : (
<Home /> //I want to Redirect to the Home Page with a flash message if user is not logged in
)
)}
/>
<Route path="/contact" component={ContactUs} />
</Switch>
</div>
</Router>,
);
Run Code Online (Sandbox Code Playgroud) 请通过javascript为引导工具提示/弹出框传递选项的正确方法是什么:通过数据属性的工作原理如下:
<input type="text" data-toggle="tooltip" data-placement="right" data-animation="fade" data-delay="200" data-trigger="focus" data-content="foo">
Run Code Online (Sandbox Code Playgroud)
但使用 javascript 则不会:
<script>
jQuery(function ($) {
$("input").popover()({
animation:"fade",
delay: "200",
trigger:"focus",
placement: "right"
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
正确的语法是什么?