Я пытаюсь использовать REACT JS в MVC 4.x Framework.Я могу установить тег заголовка с помощью REACT.Однако я не могу установить заголовок страницы с помощью REACT.JS в ASP.NET.
Я попытался импортировать DocumentTitle, чтобы установить заголовок страницы.
import DocumentTitle from 'response-document-title ';
App.JS -
класс Hello extends React.Component {
componentDidMount() {
document.title = "Home Page"
}
render() {
return (
<DocumentTitle title='Home'>
<h1>
Hello {this.props.name} {this.props.time}
</h1>
</DocumentTitle>
);
}
}
Index.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, который я установил в контроллере.Тем не менее, он показывает по умолчанию -