我是js和reaction的新手,一直在try 创建一个个人网站.我已经挣扎了几个小时,只是想创建一个单独的页面,在那里我可以把我的项目放在那里,并从我的主页链接到它.简历链接有效,但仅因为IM直接链接到PDF.

下面是我的page.js的外观:

'use client'
import Head from 'next/head';
import {BsFillMoonStarsFill} from 'react-icons/bs';
import {AiFillLinkedin, AiFillGithub} from "react-icons/ai";
import { BrowserRouter, Link } from 'react-router-dom';
import { createContext } from 'react'

const Context = createContext()


export default function Home() {
  return (

    <div>
      <Head>
        <title>First Last Portfolio</title>
        <meta name = "description" content = "Text"></meta>
        <link rel = "icon" href = "/faviocon.ico" />
      </Head>
      <main className='bg-teal-400 px-10 md:px-20 lg:px-30'>
        <section className=" bg-teal-400 min-h-screen">
          <nav className='py-10 mb-12 flex justify-between'>
            <h1 className='text-xl font-mono'>Name</h1>
            <ul className='flex items-center'>
              <li>
                <BsFillMoonStarsFill className='cursor-pointer text-2xl'/>
              </li>
              <li>
              <BrowserRouter>
              <Link className='bg-teal-950 text-gray-200 px-4 py-2 rounded-md ml-6' target="_blank" rel="noopener noreferrer"  to="/resume.pdf">
                  Resume
              </Link>
              
              <Link className='bg-teal-950 text-gray-200 px-4 py-2 rounded-md ml-6' to="/projects">
                  Portfolio
              </Link>
              </BrowserRouter>
              </li>
            </ul>
          </nav>
          <div className='text-center p-10'>
            <h2 className='text-5xl py-2 text-teal-950 font-medium md:text-6xl'>First Last</h2>
            <h3 className='text-2xl py-2 md:text-3xl'>Software Engineer</h3>
            <p className='text-md py-5 leading-8 text-gray-800 md:text-xl max-w-lg mx-auto'>blah blah blas this is what I do</p>
          </div>
          <div className='text-5xl flex justify-center gap-16 py-3 text-teal-950'>
            <AiFillLinkedin />
            <AiFillGithub />
          </div>
        </section>
        <section>
    <div style={{display: 'flex', flexDirection: 'row', alignItems: 'center'}}>
        <div style={{flex: 1, height: '1px', backgroundColor: 'black'}}/>

            <div>
              <h3 className='text-lg font-medium' style={{width: '100px', textAlign: 'center'}}>Portfolio</h3>
            </div>

        <div style={{flex: 1, height: '1px', backgroundColor: 'black'}}/>
    </div>

          <div className='text-center shadow-lg p-10'>
            <h3 className='text-lg font-medium'>Project 1</h3>
            <p>
              Some information about the project should probably be here
            </p>
          </div>
        </section>
      </main>
    </div>

  );
}

我的index.js是这样的:



import ReactDOM from "react-dom";
import {BrowserRouter as Router, Link, Route, Routes } from 'react-router-dom';

import Layout from "./layout";
import Home from "./page";
import Resume from "./resume";
import Projects from "./projects";
//import { BrowserRouter } from "react-router-dom";

export default function App() {
    
  return (

    <BrowserRouter>
      <Routes>
        <Route path="/" element={<Layout />}>
          <Route index element={<Home />} />
          <Route path="/resume" element={<Resume />} />
          <Route path="/projects" element={<Projects />} />   
          </Route>               
      </Routes>
    </BrowserRouter>

  );
}

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

这是我的项目.js:

import React from "react";

const Projects = () => {
  
  const projects = [
    { id: 1, title: "Project 1", description: "Description of Project 1" },
    { id: 2, title: "Project 2", description: "Description of Project 2" },
  ];

  return (
    <div>
      <h1>Projects</h1>
      <ul>
        {projects.map((project) => (
          <li key={project.id}>
            <h2>{project.title}</h2>
            <p>{project.description}</p>
          </li>
        ))}
      </ul>
    </div>
  );
};

export default Projects;

我最初收到"无法使用路由外的链接",现在已经解决了,但我的IM没有被路由到我的页面.

推荐答案

对你学习react 和脚本很有帮助.

这里有几件事

  • Reaction是一个拥有许多不同框架和工具的大型社区.他们并不都在一起工作
  • Js是一种混合了服务器端渲染和react.js的工具.它与许多专注于纯客户端内容的工具不兼容
  • 您安装了‘action-router-dom’,它不能与next.js一起工作,因为它是以客户端为中心的
  • This next.js page will show you how to do routing within their framework.您可以使用它来创建新页面并查看该新页面如何连接到路径
  • This link will show you how to add a link to another page
  • 我建议删除"REACT-ROUTER-DOM"包,完全专注于next.js工具.
  • 许多组件库都可以工作,但对于next.js,路由肯定需要以next.js的方式完成

Reactjs相关问答推荐

安装后未渲染tailwind

在REACT-RUTER-DOMV6中使用通用页面包装组件有问题吗?

获取未捕获的错误:Gatsby生产版本上的最小化react 错误#418

子路径上未定义useMatches句柄

如何在物料界面react 的多选菜单中设置最大 Select 数限制

在ReactJS的monaco编辑器中添加美人鱼语法

shadcn输入+窗体+Zod;一个部件正在改变要被控制的不受控制的输入;

如何动态地改变<; Select >;React和Tailwind元素?

如何获取用户在 GooglePlacesAutocomplete 中输入的文本?

在Vite React上获取Amplify的环境变量

如何在Next.js应用程序中为路由[slug]生成.html文件?

React对象值下降2次而不是1次

在复选框中react 检索选中的值

需要在窗口调整大小时更新 React 组件

我如何在所有组件中使用 Chakra UI toast?

list 组件未按预期运行

Cypress ,重试不再附加到 DOM 的元素

如何通过 Material ui select 使下拉菜单下拉

无法重用我的组件,它只显示 1 次

useEffect 仅在跟随链接后有效,不适用于直接链接