Skip to main content
previewFile(file){
    
    if(!this.usedInCommunity){
        
        this[NavigationMixin.Navigate]({
            type: 'standard__namedPage',
            attributes: {
                pageName: 'filePreview'
            },
            state : {
                selectedRecordId: file.ContentDocumentId
            }
        });
    } else if(this.usedInCommunity){
        
        this[NavigationMixin.Navigate]({
            type: 'standard__webPage',
            attributes: {
                url: file.fileUrl
            }
        }, false );
    }
    
}
    previewFile(file){
        
        if(!this.usedInCommunity){
            
            this[NavigationMixin.Navigate]({
                type: 'standard__namedPage',
                attributes: {
                    pageName: 'filePreview'
                },
                state : {
                    selectedRecordId: file.ContentDocumentId
                }
            });
        } else if(this.usedInCommunity){
            
            this[NavigationMixin.Navigate]({
                type: 'standard__webPage',
                attributes: {
                    url: file.fileUrl
                }
            }, false );
        }
        
    }
previewFile(file){
    
    if(!this.usedInCommunity){
        
        this[NavigationMixin.Navigate]({
            type: 'standard__namedPage',
            attributes: {
                pageName: 'filePreview'
            },
            state : {
                selectedRecordId: file.ContentDocumentId
            }
        });
    } else if(this.usedInCommunity){
        
        this[NavigationMixin.Navigate]({
            type: 'standard__webPage',
            attributes: {
                url: file.fileUrl
            }
        }, false );
    }
    
}
    previewFile(file){
        
        if(!this.usedInCommunity){
            
            this[NavigationMixin.Navigate]({
                type: 'standard__namedPage',
                attributes: {
                    pageName: 'filePreview'
                },
                state : {
                    selectedRecordId: file.ContentDocumentId
                }
            });
        } else if(this.usedInCommunity){
            
            this[NavigationMixin.Navigate]({
                type: 'standard__webPage',
                attributes: {
                    url: file.fileUrl
                }
            }, false );
        }
        
    }
Source Link
dino ursic
  • 2.3k
  • 1
  • 16
  • 21

The NavigationMixin solution should work as well, with minor modification. According to this blog post, rather than using NavigationMixin.Navigate with type argument standard__namedPage and ContentDocumentId, you should be using standard__webPage along with the file URL.

previewFile(file){
    
    if(!this.usedInCommunity){
        
        this[NavigationMixin.Navigate]({
            type: 'standard__namedPage',
            attributes: {
                pageName: 'filePreview'
            },
            state : {
                selectedRecordId: file.ContentDocumentId
            }
        });
    } else if(this.usedInCommunity){
        
        this[NavigationMixin.Navigate]({
            type: 'standard__webPage',
            attributes: {
                url: file.fileUrl
            }
        }, false );
    }
    
}