force:hasRecordId is meant only for the Lightning experience and App builder and not the community builderuse .force:hasRecordId
as documented here
For the communityExperience builder the way I have managed to get the record idID is as below
Create a design file like below
<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,forceflexipage:appHostableavailableForAllPageTypes,flexipageforce:availableForAllPageTypes">hasRecordId">
<!--ATTRIBUTES DECLARATION -->
<aura:attribute name="recordId" type="String" default="{!recordId}"/>
<aura:handler name="init" value="{!this}" action="{!c.getrecord}" />
</aura:component>
LetsLet's get the Id now in our JS controller
({
getresults: function(component, event, helper) {
console.log(component.get("v.recordId"));//print the Id
}
})