React路由器v6.3.0 http:// localhost:3000/https://example.com/

发布于 2025-02-14 01:50:41 字数 3026 浏览 0 评论 0原文

index.jsx is

import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import reportWebVitals from './reportWebVitals';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <React.StrictMode>
    <BrowserRouter>
     <App />
  </BrowserRouter>
 </React.StrictMode>,
);

reportWebVitals();

app.jsx is

import { ThemeProvider } from 'styled-components';
import { lightTheme } from './components/Themes';
import { Route, Routes, useLocation } from 'react-router';
import { About } from './components/About';
import { Main } from './components/Main';
import { Blog } from './components/Blog';
import { Work } from './components/Work';
import { Skill } from './components/Skill';
import { AnimatePresence } from 'framer-motion';
import { Music } from './components/partials/Music';

function App() {
  const location = useLocation();

   return (
<>
  <ThemeProvider theme={lightTheme}>
    <Music />
    <AnimatePresence exitBeforeEnter>
      <Routes location={location} key={location.pathname}>
        <Route path="/" element={<Main />} />
        <Route path="/about" element={<About />} />
        <Route path="/blog" element={<Blog />} />
        <Route path="/work" element={<Work />} />
        <Route path="/skill" element={<Skill />} />
      </Routes>
    </AnimatePresence>
  </ThemeProvider>
</>
  );
 }

export default App;

secialicons.jsx

import React from 'react';
import { NavLink } from 'react-router-dom';
import styled from 'styled-components';
import { motion } from 'framer-motion';
import { Facebook, Github, Twitter, YouTube } from '../AllSvgs';
import { DarkTheme } from '../Themes';

export const SocialIcons = (props) => {
  return (
<div className="socialIcon">
  <motion.div
    initial={{ transform: 'scale(0)' }}
    animate={{ scale: [0, 1, 1.5, 1] }}
    transition={{ type: 'spring', duration: 1, delay: 1 }}
  >
    <NavLink
      style={{ color: 'inherit' }}
      target="_blank"
      to={{ pathname: 'https://github.com/faha1999' }}
    >
      <Github
        width={25}
        height={25}
        fill={props.theme === 'dark' ? DarkTheme.text : DarkTheme.body}
      />
    </NavLink>
  </motion.div>

</div>
 );
};

当我单击GitHub图标React React Roureter React React React React Rection Rection Rections将链接重定向到链接,如http:// Localhost:3000/https://github.com/或 http://example.com/https:/https://github.com/ 通常像IS https://github.com/

我不知道为什么每次此链接都会这样生成。

如何解决这个问题?

Index.jsx is

import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import reportWebVitals from './reportWebVitals';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <React.StrictMode>
    <BrowserRouter>
     <App />
  </BrowserRouter>
 </React.StrictMode>,
);

reportWebVitals();

App.jsx is

import { ThemeProvider } from 'styled-components';
import { lightTheme } from './components/Themes';
import { Route, Routes, useLocation } from 'react-router';
import { About } from './components/About';
import { Main } from './components/Main';
import { Blog } from './components/Blog';
import { Work } from './components/Work';
import { Skill } from './components/Skill';
import { AnimatePresence } from 'framer-motion';
import { Music } from './components/partials/Music';

function App() {
  const location = useLocation();

   return (
<>
  <ThemeProvider theme={lightTheme}>
    <Music />
    <AnimatePresence exitBeforeEnter>
      <Routes location={location} key={location.pathname}>
        <Route path="/" element={<Main />} />
        <Route path="/about" element={<About />} />
        <Route path="/blog" element={<Blog />} />
        <Route path="/work" element={<Work />} />
        <Route path="/skill" element={<Skill />} />
      </Routes>
    </AnimatePresence>
  </ThemeProvider>
</>
  );
 }

export default App;

SocialIcons.jsx is

import React from 'react';
import { NavLink } from 'react-router-dom';
import styled from 'styled-components';
import { motion } from 'framer-motion';
import { Facebook, Github, Twitter, YouTube } from '../AllSvgs';
import { DarkTheme } from '../Themes';

export const SocialIcons = (props) => {
  return (
<div className="socialIcon">
  <motion.div
    initial={{ transform: 'scale(0)' }}
    animate={{ scale: [0, 1, 1.5, 1] }}
    transition={{ type: 'spring', duration: 1, delay: 1 }}
  >
    <NavLink
      style={{ color: 'inherit' }}
      target="_blank"
      to={{ pathname: 'https://github.com/faha1999' }}
    >
      <Github
        width={25}
        height={25}
        fill={props.theme === 'dark' ? DarkTheme.text : DarkTheme.body}
      />
    </NavLink>
  </motion.div>

</div>
 );
};

When I click the GitHub icon React router redirects to the link like http://localhost:3000/https://github.com/ or http://example.com/https://github.com/ where usually the like is https://github.com/.

I have no idea why every time this link is generating like this.

How to solve this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

↘紸啶 2025-02-21 01:50:41

您可以将直接标签使用并重定向到以下外部站点,希望这对您有用。通常,我们可以将其重定向到外部站点,我们可以使用标签,并且可以按预期工作。

import React from 'react';
import { NavLink } from 'react-router-dom';
import styled from 'styled-components';
import { motion } from 'framer-motion';
import { Facebook, Github, Twitter, YouTube } from '../AllSvgs';
import { DarkTheme } from '../Themes';

export const SocialIcons = (props) => {
  return (
<div className="socialIcon">
  <motion.div
    initial={{ transform: 'scale(0)' }}
    animate={{ scale: [0, 1, 1.5, 1] }}
    transition={{ type: 'spring', duration: 1, delay: 1 }}
  >
    <a
      style={{ color: 'inherit' }}
      target="_blank"
      href='https://github.com/faha1999'
    > {/* Here I change from NavLing to anchor tag.  */}
      <Github
        width={25}
        height={25}
        fill={props.theme === 'dark' ? DarkTheme.text : DarkTheme.body}
      />
    </a>
  </motion.div>

</div>
 );
};

You can use the direct tag and redirect to the external site like below, hope this works for you. Normally redirecting to the external site we can use tag, and it will work as expected.

import React from 'react';
import { NavLink } from 'react-router-dom';
import styled from 'styled-components';
import { motion } from 'framer-motion';
import { Facebook, Github, Twitter, YouTube } from '../AllSvgs';
import { DarkTheme } from '../Themes';

export const SocialIcons = (props) => {
  return (
<div className="socialIcon">
  <motion.div
    initial={{ transform: 'scale(0)' }}
    animate={{ scale: [0, 1, 1.5, 1] }}
    transition={{ type: 'spring', duration: 1, delay: 1 }}
  >
    <a
      style={{ color: 'inherit' }}
      target="_blank"
      href='https://github.com/faha1999'
    > {/* Here I change from NavLing to anchor tag.  */}
      <Github
        width={25}
        height={25}
        fill={props.theme === 'dark' ? DarkTheme.text : DarkTheme.body}
      />
    </a>
  </motion.div>

</div>
 );
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文