c# - 如何在 app.js - React JS 中导入 react-document-title?
问题描述
我正在尝试在 MVC 4.x 框架中使用 REACT JS。我可以使用 REACT 设置标题标签。但是,我无法在 ASP.NET 中使用 REACT.JS 设置页面标题。
我尝试导入 DocumentTitle 来设置页面的标题。
从 'react-document-title' 导入 DocumentTitle;
应用程序.JS -
类 Hello 扩展 React.Component {
componentDidMount() {
document.title = "Home Page"
}
render() {
return (
<DocumentTitle title='Home'>
<h1>
Hello {this.props.name} {this.props.time}
</h1>
</DocumentTitle>
);
}
}
索引.cshtml
@using React.Web.Mvc
<h2>Index</h2>
<!-- React Component -->
<!-- Hello is react component-->
<!-- name is props -->
@Html.React("Hello", new
{
name = "BC",
time = DateTime.Now.Year,
websiteTitle = ViewBag.message
})
我希望根据我在控制器中设置的 ViewBag.message 设置页面标题。但是,它显示的是默认值 -
解决方案
推荐阅读
- java - Java合并文件
- html - 两个简单的 HTML & CSS 问题
- networking - Zookeeper 僵尸客户端
- c++ - C++ 中的时间复杂度
- go - 在 ubuntu 上安装协议缓冲区有困难
- jquery - 如何在 span 标签中写入值?
- python - 如何将函数映射到表示为 numpy 数组的图像中的每个像素?
- java - 我需要找到具有与 slowChop 类似功能的快速斩波
- windows - Windows 目标构建:错误:C 编译器在配置时无法创建可执行文件
- python-3.x - 如何使用 LibreOffice 宏将 os.system() 命令写入 python 脚本并执行它?