umi 获取路由参数

在config.js里 添加路由

{
             // name: 'applications',
             // icon: 'smile',
              path: '/blog/show',
              component: './blog/ShowSingleArticle',
            },

在路由query的参数存在props.location.query 结构里

const EditArticle: FC> = (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 (
   
      
       
        
); }; export default EditArticle;

你可能感兴趣的:(react,前端,javascript,vue.js)