diff --git a/webapp/src/components/sidebar/sidebarBoardItem.tsx b/webapp/src/components/sidebar/sidebarBoardItem.tsx index 4078bdd16..f7fb7c4c6 100644 --- a/webapp/src/components/sidebar/sidebarBoardItem.tsx +++ b/webapp/src/components/sidebar/sidebarBoardItem.tsx @@ -32,10 +32,17 @@ const SidebarBoardItem = React.memo((props: Props) => { const [collapsed, setCollapsed] = useState(false) const intl = useIntl() const history = useHistory() - const match = useRouteMatch() + const match = useRouteMatch<{boardId: string, viewId?: string, cardId?: string, workspaceId?: string}>() const showBoard = useCallback((boardId) => { - const newPath = generatePath(match.path, {...match.params, boardId: boardId || ''}) + // if the same board, reuse the match params + // otherwise remove viewId and cardId, results in first view being selected + const params = {...match.params, boardId: boardId || ''} + if (boardId !== match.params.boardId) { + params.viewId = undefined + params.cardId = undefined + } + const newPath = generatePath(match.path, params) history.push(newPath) }, [match, history]) diff --git a/webapp/src/pages/boardPage.tsx b/webapp/src/pages/boardPage.tsx index 58adc05b3..cd97d3533 100644 --- a/webapp/src/pages/boardPage.tsx +++ b/webapp/src/pages/boardPage.tsx @@ -110,8 +110,10 @@ const BoardPage = (props: Props): JSX.Element => { } Utils.log(`attachToBoard: ${boardId}`) - const viewIsFromBoard = boardViews.some((view) => view.id === viewId) - if ((!viewId || !viewIsFromBoard) && boardViews.length > 0) { + + // Ensure boardViews is for our boardId before redirecting + const isCorrectBoardView = boardViews.length > 0 && boardViews[0].parentId === boardId + if (!viewId && isCorrectBoardView) { const newPath = generatePath(match.path, {...match.params, boardId, viewId: boardViews[0].id}) history.replace(newPath) return