Comments (5)
Can you provide some code? When you say it doesn't work, what do you mean?
Are you calling navigate(to)
on a route defined in React Router? That is, you can't navigate to an external route via the hook.
from react-router.
Can you provide some code? When you say it doesn't work, what do you mean?
Are you calling
navigate(to)
on a route defined in React Router? That is, you can't navigate to an external route via the hook.
export const routes = {
login: '/',
forgotPassword: '/forgot-password',
newPassword: '/new-password/:userId/:code',
main: '/main',
chat: '/chat',
} as const;
export const useRouter = () => {
const router = createBrowserRouter([
{
path: routes.login,
element: <LoginPage />,
},
{
path: routes.forgotPassword,
element: <ForgotPasswordPage />,
},
{
path: routes.newPassword,
element: <NewPasswordPage />,
},
{
path: routes.main,
element: <MainPage />,
},
{
path: routes.chat,
element: <ChatPage />,
},
{
path: '*',
element: <Navigate to={routes.login} replace />,
},
]);
return router;
};
my main.tsx
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import './index.css'
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>,
)
my App
import { RouterProvider } from 'react-router-dom';
import { useRouter } from './utils/routes';
import { ThemeProvider } from '@emotion/react';
import { createTheme } from '@mui/material/styles';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
function App() {
const queryClient = new QueryClient();
const router = useRouter();
const theme = createTheme({
palette: {
primary: {
main: '#399190',
dark: '#2E6461',
light: '#5FB2B3',
contrastText: '#FFFFFF',
},
secondary: {
main: '#4A64A2',
dark: '#254B94',
light: '#94A3C7',
contrastText: '#FFFFFF',
},
error: {
main: '#D32F2F',
dark: '#C62828',
light: '#EF5350',
contrastText: '#FFFFFF',
},
warning: {
main: '#EF6C00',
dark: '#D96303',
light: '#FF9800',
contrastText: '#FFFFFF',
},
info: {
main: '#0288D1',
dark: '#01579B',
light: '#03A9F4',
contrastText: '#FFFFFF',
},
success: {
main: '#2E7D32',
dark: '#1B5E20',
light: '#4CAF50',
contrastText: '#FFFFFF',
},
},
typography: {
fontFamily: 'Roboto',
},
});
return (
<QueryClientProvider client={queryClient}>
<ThemeProvider theme={theme}>
<RouterProvider router={router} />
</ThemeProvider>
</QueryClientProvider>
);
}
export default App;
and I try use navigate in my login page. Locally everything works, but on the prod site navigate doesn't work
const onConfirmAuthorization = () => {
navigate(routes.main);
};
from react-router.
When you say it "doesn't work", do you mean it doesn't navigate to /main
?
Are you sure the onConfirmationAuthorization
function is being called?
Have you tried just adding a button with an onClick
handler that navigates to verify navigate
works?
from react-router.
When you say it "doesn't work", do you mean it doesn't navigate to
/main
?Are you sure the
onConfirmationAuthorization
function is being called?Have you tried just adding a button with an
onClick
handler that navigates to verifynavigate
works?
yes, I tried
from react-router.
update, I've got the site deployed on Amazon S3 bucket
from react-router.
Related Issues (20)
- [Bug]: useBlocker is not working HOT 5
- [Bug]: Cannot navigate in windows production HOT 2
- [Bug]: Unable to Pass State Using useNavigate When Navigating Back to Previous Route HOT 1
- [Bug]: Navigation don't work with createBrowserRouter sometimes HOT 2
- [Bug]: lazy loaded module error in nested router is catched only by the parent route with the * wildcard, not by the `errorElement` in the nested router HOT 2
- [Bug]: `fetcher.data` is define when submitting via `fetcher.submit` but is undefined when submitting a `fetcher.Form` HOT 3
- [Bug]: Navigation from '//' pathname does not work; path '*' is not matching the '//' page HOT 1
- [Bug]: Getting "A router only supports one blocker at a time" warning when running your navigation-blocking example HOT 2
- [Bug]: `setSearchParams` do not provide the latest queryString passed as argument to `navigate` HOT 3
- [Bug]: React Router swallows render error HOT 1
- [Bug]: useBlocker in createBrowserRouter is not working
- [Bug]: useLocation value being null when 0 is set as the state value of useNavigate
- [Docs]: for useSearchParams, functional updates should be explained in more detail HOT 3
- [Bug]: React router doesn't handle 'content://' URLs
- [Bug]: the state is not destroyed in the useFetcher hook with key parametr
- [Bug]: Outlet component remounts in production when changing state above it HOT 2
- [Bug]: loader of Route running even if Route / Router is not rendered HOT 2
- [Docs]: Docs for shouldRevalidate make it sound like it is only for opting out
- [Bug]: `useLocation` out of sync with `history.location`, leads to potential renders of unmatched `Route`s
- [Bug]: useLoaderData triggers component re rendering even if the route remains unchanged HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-router.