How Get record in in lightning component in communities
force:hasRecordId is meant only for the Lightning experience and App builder and not the community builder .
<design:component>
<design:attribute name="recordId" label="recordId" description="Salesforce Id of the record" />
</design:component>
Create an attribute mapping to the design variable
<aura:component implements="forceCommunity:availableForAllPageTypes,force:appHostable,flexipage:availableForAllPageTypes">
<!--ATTRIBUTES DECLARATION -->
<aura:attribute name="recordId" type="String" default="{!recordId}"/>
<aura:handler name="init" value="{!this}" action="{!c.getrecord}" />
</aura:component>
Lets get the Id now in our JS controller
({
getresults: function(component, event, helper) {
console.log(component.get("v.recordId"));//print the Id
}
})