Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

use next.js built-in router hooks#759

Merged
mydearxym merged 2 commits intodevfromwith-router
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletionsrc/components/Buttons/ArrowButton.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,7 +65,7 @@ const ArrowButton = ({
}

ArrowButton.propTypes = {
children: T.oneOfType(T.string, T.node),
children: T.oneOfType([T.string, T.node]),
size: T.oneOf(['tiny', 'small', 'medium', 'large']),
direction: T.oneOf(['left', 'right']),
transparentFirst: T.bool,
Expand Down
2 changes: 1 addition & 1 deletionsrc/components/Buttons/Button.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -33,7 +33,7 @@ const Button = ({ children, ghost, type, onClick, size, className }) => {
}

Button.propTypes = {
children: T.oneOfType(T.string, T.node),
children: T.oneOfType([T.string, T.node]),
ghost: T.bool,
type: T.oneOf(['primary', 'red', 'ghost']),
size: T.oneOf(['default', 'small']),
Expand Down
2 changes: 1 addition & 1 deletionsrc/components/NaviMenu/index.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -123,7 +123,7 @@ NaviMenu.propTypes = {
title: T.string,
icon: T.string,
displayType: T.string,
fixedIcon: T.oneOfType(T.string, T.node),
fixedIcon: T.oneOfType([T.string, T.node]),
pinNumber: T.number,
childMenu: T.arrayOf(
T.shape({
Expand Down
7 changes: 4 additions & 3 deletionssrc/components/Navigator/MainEntries.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import React from 'react'
import T from 'prop-types'
import Link from 'next/link'
import {withRouter } from 'next/router'
import {useRouter } from 'next/router'

import { ICON_CMD } from '@/config'
import { ROUTE } from '@/constant'
Expand All@@ -14,7 +14,8 @@ import { Wrapper, DotDivider, SiteLink, Icon } from './styles/main_entries'

const splitMargin = '7px'

const MainEntries = ({ router, type }) => {
const MainEntries = ({ type }) => {
const router = useRouter()
const mainPath = getRouteMainPath(router.asPath)

return (
Expand DownExpand Up@@ -95,4 +96,4 @@ MainEntries.defaultProps = {
type: null,
}

export default React.memo(withRouter(MainEntries))
export default React.memo(MainEntries)
7 changes: 4 additions & 3 deletionssrc/components/Navigator/index.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,7 @@
import React from 'react'
import T from 'prop-types'
import { contains } from 'ramda'
import {withRouter } from 'next/router'
import {useRouter } from 'next/router'

import { ROUTE, C11N } from '@/constant'
import { buildLog, getRoutePathList } from '@/utils'
Expand All@@ -18,7 +18,8 @@ import BriefView from './BriefView'
/* eslint-disable-next-line */
const log = buildLog('c:Navigator:index')

const Navigator = ({ curCommunity, layout, router }) => {
const Navigator = ({ curCommunity, layout }) => {
const router = useRouter()
const [mainPath, subPath] = getRoutePathList(router.asPath)

if (
Expand DownExpand Up@@ -49,4 +50,4 @@ Navigator.defaultProps = {
layout: C11N.DIGEST,
}

export default React.memo(withRouter(Navigator))
export default React.memo(Navigator)
2 changes: 1 addition & 1 deletionsrc/components/Switcher/IconSwitcher.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -70,7 +70,7 @@ IconSwitcher.propTypes = {
items: T.arrayOf(
T.shape({
iconSrc: T.string,
localIcon: T.oneOfType(T.string, T.node),
localIcon: T.oneOfType([T.string, T.node]),
key: T.string,
})
).isRequired,
Expand Down
43 changes: 5 additions & 38 deletionssrc/containers/Route/index.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,49 +5,16 @@
*/

import React from 'react'
import { inject, observer } from 'mobx-react'
import { withRouter } from 'next/router'
import { useRouter } from 'next/router'

// import Link from 'next/link'

import { buildLog, storePlug } from 'utils'
import { init, uninit } from './logic'

/* eslint-disable-next-line */
const log = buildLog('C:Route')

class RouteContainer extends React.Component {
componentDidMount() {
const { route, router } = this.props
init(route, router)
}

componentWillUnmount() {
uninit()
}

render() {
return <React.Fragment />
}
}

export default inject(storePlug('route'))(observer(withRouter(RouteContainer)))

/*
import React from 'react'
import { withRouter } from 'next/router'

// import Link from 'next/link'

import { connectStore, buildLog } from '@/utils'
import { connectStore } from '@/utils'
import { useInit } from './logic'

const RouteContainer = ({ route, router }) => {
const RouteContainer = ({ route }) => {
const router = useRouter()
useInit(route, router)

return <React.Fragment />
}

export default connectStore(withRouter(RouteContainer))

*/
export default connectStore(RouteContainer)
16 changes: 2 additions & 14 deletionssrc/containers/Route/logic.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,20 +15,6 @@ const browserHistoryBtnClicked = popstate => {
// ###############################
// init & uninit
// ###############################
export const init = (_store, routeObj) => {
if (store) return false

store = _store
// sync init router info
const { mainPath, subPath } = parseURL(routeObj)
const { query } = routeObj

store.mark({ mainPath, subPath, query })

Global.onpopstate = browserHistoryBtnClicked
}

export const uninit = () => {}

export const useInit = (_store, routeObj) => {
useEffect(() => {
Expand All@@ -42,3 +28,5 @@ export const useInit = (_store, routeObj) => {
Global.onpopstate = browserHistoryBtnClicked
}, [_store, routeObj])
}

export const holder = 1

[8]ページ先頭

©2009-2025 Movatter.jp