backstage: π Backstage HeaderTabs with v1.26.0 cause breaking changes
π Description
I can see that Backstage has introduced tabs as Links in v1.26.0, with the href attribute. But with the change, you are removing leading slashes (/), and making paths relative which is breaking the navigation.
There are 2 issues,
- If we had absolute paths before, eg. /team/members, introducing the following code change makes this path relative and so it gets appended to the URL and doesnβt redirects to the correct page.
// HeaderTabs.tsx function removeLeadingSlash(path: string) { return path.replace(/^\//, ''); } ... component={Link} to={removeLeadingSlash(tab.id)} ... - If I change it to relative path, if it is outside of nested Routes, it works fine. But if it is in a route element component, the redirection doesnβt work anymore. Though if we use the absolute path, and the leading slash is not removed, it works.
π Expected behavior
I wanted to understand the reason of introducing the method to remove leading slashes and make the path relative on purpose. Ideally, it should redirect to the correct path no matter if we pass absolute or relative path.
π Actual Behavior with Screenshots
It appends the path in the URL,
π Reproduction steps
For any HeaderTab implementation,
-
When I pass absolute path,
const tabs = [ { label: 'Tab 1', path: '/plugin-name' }, { label: 'Tab 2', path: '/plugin-name/coverage' }, { label: 'Tab 3', path: '/plugin-name/tab-3' }, ]; ... <HeaderTabs selectedIndex={selectedIndex} tabs={tabs.map(({ label, path, tabProps }) => ({ id: path, label, tabProps, }))} /> -
The issue remains the same even when I have relative paths,
const tabs = [ { label: 'Tab 1', path: '' }, { label: 'Tab 2', path: 'coverage' }, { label: 'Tab 3', path: 'tab-3' }, ]; ... <HeaderTabs selectedIndex={selectedIndex} tabs={tabs.map(({ label, path, tabProps }) => ({ id: path, label, tabProps, }))} />
For 2, the issue occurs when I use the above code inside Content.tsx from below (because Content gets re-rendered on click of tab and it updates the href),
```
<Routes>
<Route path="/" element={<DashboardContent />} />
<Route
path="/content"
element={<Content />}
/>
</Routes>
```
π Provide the context for the Bug.
No response
π₯οΈ Your Environment
OS: Darwin 23.4.0 - darwin/arm64 node: v18.18.0 yarn: 1.22.19 cli: 0.26.6 (installed) backstage: 1.27.5
@backstage/core-components: 0.14.7
π Have you spent some time to check if this bug has been raised before?
- I checked and didnβt find similar issue
π’ Have you read the Code of Conduct?
- I have read the Code of Conduct
Are you willing to submit PR?
Yes I am willing to submit a PR!
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 17 (9 by maintainers)
Thanks for sharing @malhotraashna. I added a βneeds-discussionβ label to review the extended uses cases with our team.