added redirect after login (#325)

The old behaviour was: You open a page without being authorized, you are getting redirected to /login that
redirects you after a successful authentication to /dashboard. This is really annoying if you want to open
listenings directly from your notification adapter for example. This commit introduces a method to redirect
you back to the original page you opened after the authentication process by adding the navigation of the
opened page as state to the navigation to /login. The login component than unpacks the state that contains
the old navigation and redirects the user back to path from the original navigation. The path /dashboard is
used as a fallback if no navigation in the state is present.
This commit is contained in:
AdriDevelopsThings
2026-06-09 11:59:18 +02:00
committed by GitHub
parent c132e64437
commit 6c7d655277
2 changed files with 6 additions and 4 deletions

View File

@@ -8,7 +8,7 @@ import React, { useEffect } from 'react';
import cityBackground from '../../assets/city_background.jpg';
import Logo from '../../components/logo/Logo';
import { xhrPost } from '../../services/xhr';
import { useNavigate } from 'react-router-dom';
import { useLocation, useNavigate } from 'react-router-dom';
import { useActions, useSelector } from '../../services/state/store';
import { Input, Button, Banner } from '@douyinfe/semi-ui-19';
@@ -24,6 +24,7 @@ export default function Login() {
const [error, setError] = React.useState(null);
const demoMode = useSelector((state) => state.demoMode.demoMode || false);
const navigate = useNavigate();
const location = useLocation();
useEffect(() => {
async function init() {
@@ -52,7 +53,7 @@ export default function Login() {
}
await actions.user.getCurrentUser();
navigate('/dashboard');
navigate(location.state?.from?.pathname || '/dashboard');
};
return (