Skip to content

Commit

Permalink
1. base url
Browse files Browse the repository at this point in the history
  • Loading branch information
JingDeZhe committed Jun 7, 2024
1 parent 82c4187 commit 04387e8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/pages/Home.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Link } from 'react-router-dom'

export const Home = () => {
return (
<div className="home p-2">
<a href="/chat">Chat</a>
<Link to="/chat">Chat</Link>
</div>
)
}
3 changes: 2 additions & 1 deletion src/pages/chat/MessageDisplay.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { appendBase } from '@/utils/main'
import { server } from './db/server'
import Markdown from 'react-markdown'

export const MessageDisplay = ({ message }) => {
const { message: content, type } = message
const [avatar, setAvatar] = useState('/img/avatar-0.jpg')
const [avatar, setAvatar] = useState(appendBase('/img/avatar-0.jpg'))

useEffect(() => {
server.getAvatar(message.fromId).then(setAvatar)
Expand Down
19 changes: 12 additions & 7 deletions src/router/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ import { chatRoute } from '../pages/chat/route'
import { ErrorPage } from '../pages/ErrorPage'
import { Home } from '@/pages/Home'

export const router = createBrowserRouter([
export const router = createBrowserRouter(
[
{
path: '/',
element: <Home />,
errorElement: <ErrorPage />,
},
chatRoute,
],
{
path: '/',
element: <Home />,
errorElement: <ErrorPage />,
},
chatRoute,
])
basename: '/xiazhi-react',
}
)
4 changes: 4 additions & 0 deletions src/utils/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,7 @@ export const localGet = (k) => {
export const localDel = (k) => {
localStorage.removeItem(k)
}

export const appendBase = (p) => {
return import.meta.env.BASE_URL + p
}

0 comments on commit 04387e8

Please sign in to comment.