[SalesForce] How to call lightning component from custom button

How can I call lightning component from custom button on record page?

I'm trying to call lightning component when I click custom button, but I cannot do it.

How should I set the values to make a new custom button, especially in "Behavior"?

Here's the screenshot:

enter image description here

Best Answer

As Charles T. on this post answered:

Create a Lightning Component that implements lightning:isUrlAddressable and create a link button that navigates to that component's Lightning URL, passing enough parameters to have the info you need (record ID for example). This will show full-screen rather than as a modal. Also note that the component will have to handle changes to v.pageReference to ensure it behaves correctly if a user navigates to it a second time in the same session.

Consequently, contrary to what Manish Anand says above, you don't have to embed the Lightning Component in a Lightning App. In fact, you can call Lightning Components not just from record detail buttons but also list buttons. Personally, I call lightning:isUrlAddressable Lightning Components constantly from related lists to navigate to subtabs with Lightning Component child object tables for easier management of child records. See the list button example below with two parameters passed in.

Button or Link URL:
/lightning/cmp/c__ContactInformationManager?c__recordId={!Contact.Id}&c__origin="Contact"
Display Checkboxes (for Multi-Record Selection): false

For instructions on how to use lightning:isUrlAddressable and pageReference, see here.