Skip to content

Commit

Permalink
OPHJOD-1117: Upgrade react-router to version 7
Browse files Browse the repository at this point in the history
  • Loading branch information
sauanto committed Dec 9, 2024
1 parent 77e2f42 commit c4af5c5
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 50 deletions.
74 changes: 42 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"react-helmet-async": "^2.0.5",
"react-i18next": "^15.1.1",
"react-icons": "^5.3.0",
"react-router-dom": "^6.28.0",
"react-router": "^7.0.2",
"web-vitals": "^4.2.4"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/components/LanguageMenu/LanguageMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useLocalizedRoutes } from '@/hooks/useLocalizedRoutes';
import { langLabels, supportedLanguageCodes } from '@/i18n/config';
import { PopupList, cx } from '@jod/design-system';
import { useTranslation } from 'react-i18next';
import { Link } from 'react-router-dom';
import { Link } from 'react-router';

export interface LanguageMenuProps {
inline?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/components/NavigationBar/NavigationBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ vi.mock('@jod/design-system', () => ({
useMediaQueries: vi.fn(),
}));

vi.mock('react-router-dom', () => ({
vi.mock('react-router', () => ({
useLocation: () => ({
pathname: 'callback-url',
}),
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useLocalizedRoutes/useLocalizedRoutes.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { renderHook } from '@testing-library/react';
import { useTranslation } from 'react-i18next';
import { useMatches, useParams } from 'react-router-dom';
import { useMatches, useParams } from 'react-router';
import { Mock, beforeEach, describe, expect, it, vi } from 'vitest';
import { useLocalizedRoutes } from './useLocalizedRoutes';

// Mock the necessary hooks
vi.mock('react-router-dom', () => ({
vi.mock('react-router', () => ({
useMatches: vi.fn(),
useParams: vi.fn(),
generatePath: vi.fn((path: string, params: Record<string, string>) => {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useLocalizedRoutes/useLocalizedRoutes.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import { generatePath, useMatches, useParams } from 'react-router-dom';
import { generatePath, useMatches, useParams } from 'react-router';

export const useLocalizedRoutes = () => {
const matches = useMatches();
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useLoginLink/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useTranslation } from 'react-i18next';
import { useLocation } from 'react-router-dom';
import { useLocation } from 'react-router';

export const useLoginLink = () => {
const { i18n } = useTranslation();
Expand Down
16 changes: 8 additions & 8 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import React, { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import { HelmetProvider } from 'react-helmet-async';
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
import { createBrowserRouter, RouterProvider } from 'react-router';
import { Metric } from 'web-vitals';
import './i18n/config';
import './index.css';
import { routes } from './routes';

const router = createBrowserRouter(routes, { basename: '/ohjaaja' });
const router = createBrowserRouter(routes, {
basename: '/ohjaaja',
future: {
v7_relativeSplatPath: true,
},
});

const root = createRoot(document.getElementById('root')!);

Expand All @@ -32,12 +37,7 @@ if (process.env.NODE_ENV !== 'production') {
root.render(
<StrictMode>
<HelmetProvider>
<RouterProvider
router={router}
future={{
v7_startTransition: true,
}}
/>
<RouterProvider router={router} />
</HelmetProvider>
</StrictMode>,
);
2 changes: 1 addition & 1 deletion src/routes/Home/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Title } from '@/components';
import { HeroCard, useMediaQueries } from '@jod/design-system';
import { useTranslation } from 'react-i18next';
import { Link } from 'react-router-dom';
import { Link } from 'react-router';

interface CardsProps {
className?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/routes/Root/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react';
import { Helmet } from 'react-helmet-async';
import { useTranslation } from 'react-i18next';
import { MdClose, MdMenu } from 'react-icons/md';
import { NavLink, Outlet, ScrollRestoration } from 'react-router-dom';
import { NavLink, Outlet, ScrollRestoration } from 'react-router';
import {
LogoEuEn,
LogoEuFi,
Expand Down
2 changes: 1 addition & 1 deletion src/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import i18n from '@/i18n/config';
import { RouteObject, redirect } from 'react-router-dom';
import { RouteObject, redirect } from 'react-router';
import { Home } from './Home';
import { NoMatch, Root } from './Root';

Expand Down

0 comments on commit c4af5c5

Please sign in to comment.