1
1
mirror of https://github.com/c8r/x0.git synced 2024-08-16 17:00:24 +03:00

Adjust route naming

This commit is contained in:
Brent Jackson 2018-06-20 14:02:53 -04:00
parent a3a2acf3af
commit b8ca9b1460
6 changed files with 27 additions and 14 deletions

View File

@ -25,7 +25,7 @@ export default class App extends React.Component {
} = this.props
// built-in layout test
if (false) {
if (true) {
return (
<ScopeProvider scope={scope}>
<SidebarLayout {...this.props} />
@ -47,7 +47,7 @@ export default class App extends React.Component {
{routes.map(route => (
<li key={route.key}>
<Link to={route.href}>
{route.name} <code>({route.path})</code>
{route.name} <code>({route.dirname})</code>
</Link>
</li>
))}

6
docs/examples/Heading.md Normal file
View File

@ -0,0 +1,6 @@
# Heading
```.jsx
<Heading>Hello</Heading>
```

View File

@ -0,0 +1,5 @@
# hello
`/examples/nested/hello.md`

View File

@ -0,0 +1,4 @@
# Nested
`/examples/nested/index.md`

View File

@ -183,14 +183,7 @@ export const Nav = ({
<NavBar {...props} />
<Divider my={0} />
<UL>
{/* rename to route.type='section' */}
{routes.map(route => route.exact ? (
<LI key={route.section + '-exact'}>
<Link to={route.path} exact>
{format(route.name)} (index)
</Link>
</LI>
) : (
{routes.map(route => (
<LI key={route.key}>
{/^https?:\/\//.test(route.path) ? (
<NavLink pl={3} href={route.path}>

View File

@ -24,7 +24,6 @@ const IS_CLIENT = typeof document !== 'undefined'
const req = require.context(DIRNAME, true, /\.(js|md|mdx|jsx)$/)
const { filename, basename = '', disableScroll } = OPTIONS
const index = filename ? path.basename(filename, path.extname(filename)) : 'index'
const getComponents = req => req.keys()
.filter(minimatch.filter('!node_modules'))
@ -63,18 +62,24 @@ export const getRoutes = async (components = initialComponents) => {
module,
Component
}) => {
const exact = name === index
name = exact ? '/' : '/' + name
const exact = name === 'index'
const dirname = path.dirname(key).replace(/^\./, '')
const extname = path.extname(key)
let pathname = dirname + (exact ? '/' : name)
let pathname = dirname + (exact ? '/' : '/' + name)
const href = pathname
const initialProps = Component.getInitialProps
? await Component.getInitialProps({ path: pathname })
: {}
const meta = module.frontMatter || {}
const props = { ...meta, ...initialProps }
// for dynamic routing
pathname = props.path || pathname
if (dirname && name === 'index') {
name = path.basename(dirname)
}
return {
key,
name,