I recently faced a challenge that I initially thought would be straightforward—adding an icon to the sidebar that redirects to a specific URL. This was particularly useful since the UniFi Admin add-on didn’t offer a sidebar icon option. After spending several hours researching and experimenting, I managed to find a solution that works seamlessly. Here’s how I did it:
Step 1: Update Configuration File
The first step was modifying the configuration.yaml file. I added the following snippet, which creates a custom panel entry for the UniFi Admin interface. You can also use !include to keep your configuration organized, but for simplicity, here’s the direct addition:
yaml
Unifi Admin panel_custom:
- name: UniFi Admin
sidebar_title: UniFi Admin
sidebar_icon: mdi:alpha-u-box
url_path: unifi
module_url: /local/unifi_redirect.js
embed_iframe: false
require_admin: true
Step 2: Create the Redirect File
Next, I created a JavaScript file named unifi_redirect.js in the /config/www directory. This file handles the redirection to the UniFi system URL. Here’s the content of the file:
javascript
window.location.replace(“https:///”);
Make sure to replace <your-unifi-url> with your actual UniFi controller URL.
Step 3: Reboot and Test
After saving the changes, I rebooted the system to ensure all configurations were applied. Upon testing, the sidebar icon appeared as expected, and clicking it redirected me to the UniFi Admin interface without any issues.
Notes and Tips
- Iframe Consideration: UniFi doesn’t support being embedded in an iframe, so redirecting to a new tab was the best approach.
- Testing and Reboots: Unfortunately, each change requires a reboot to take effect. This was a minor inconvenience but necessary for testing.
- Documentation: While working through this, I noticed an undocumented feature called
html_url. If this works as intended, it could simplify the process further by eliminating the need for a separate redirect file. However, I stuck with the method that worked reliably.
This solution not only addressed my immediate need but also provided a clear template for anyone looking to add custom URL icons to their sidebar. It’s a great example of how a bit of troubleshooting and creativity can solve seemingly complex issues. I hope this guide helps others facing similar challenges!