2016-12-27 13 views
0

PARAMS不工作試圖在我的代碼庫但創建一個導航組件「...... PARAMS」導致‘意外的標記’錯誤:顯示......在我的關愛組件

render() { 
    const {router} = this.context; 
    const { 
    index, 
    onlyActiveOnIndex, 
    to, 
    children, 
    ...params 
    } = this.props; 
    const isActive = router.isActive(to, onlyActiveOnIndex); 
    const LinkComponent = index 
    ? Link 
    : IndexLink; 
    return (
    <li className={isActive 
     ? 'active' 
     : ''}> 
     <LinkComponent {...params}>{children}</LinkComponent> 
    </li> 
); 
} 

錯誤:

ERROR in ./src/components/common/NavItem.js Module build failed: SyntaxError: C:/Development/varAssignPages/src/components/common/NavItem.js: Unexpected token (16:6)

+1

在你的標題裏面寫着......道具,在你的問題裏......參數是哪一個呢? –

回答

1

您可以在JSX標記中使用擴散,但創建const時無需使用它。試試這個:

const { 
    index, 
    onlyActiveOnIndex, 
    to, 
    children, 
    params 
    } = this.props; 

// ... 

<LinkComponent {...params}>{children}</LinkComponent> 
+0

Fabian做到了這一點,直到在您的代碼庫中看到它才被捕獲。謝謝你,我感謝你的幫助。 –