在config.js里 添加路由
{
// name: 'applications',
// icon: 'smile',
path: '/blog/show',
component: './blog/ShowSingleArticle',
},
在路由query的参数存在props.location.query 结构里
const EditArticle: FC<Record<string, any>> = (props) => {
const [content, setContent] = useState("") //
const params = props.location
const getContent = useCallback(async () =>{
const articleInfo = await GetContent({ id: params.query.id})
const contentI = articleInfo.content
console.log("params", params.query.id)
setContent(contentI || "")
},[params.query.id])
// 及时销毁 editor ,重要!
useEffect(() => {
return () => {
if (editor == null) return
editor.destroy()
setEditor(null)
}
}, [editor])
useEffect(() => {
getContent()
}, [getContent])
return (
<PageContainer content="博客">
<Card><div
dangerouslySetInnerHTML={{
__html: content
}} /></Card>
</PageContainer>
);
};
export default EditArticle;