Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Commit

Permalink
fix(docz-core): base prop for router
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Mar 29, 2019
1 parent 281cb13 commit 9ca39d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 7 additions & 3 deletions core/docz-core/src/lib/Entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import * as path from 'path'
import * as crypto from 'crypto'
import slugify from '@sindresorhus/slugify'
import humanize from 'humanize-string'
import { get } from 'lodash/fp'

import {
getParsedData,
headingsFromAst,
Expand Down Expand Up @@ -54,7 +56,7 @@ export class Entry {
this.filepath = filepath
this.link = ''
this.slug = this.slugify(filepath, config.separator)
this.route = this.getRoute(parsed)
this.route = this.getRoute(parsed, config.base)
this.name = name
this.menu = parsed.menu || ''
this.headings = headingsFromAst(ast)
Expand Down Expand Up @@ -90,7 +92,9 @@ export class Entry {
return slugify(fileWithoutExt, { separator })
}

private getRoute(parsed: any): string {
return parsed && parsed.route ? parsed.route : `/${this.slug}`
private getRoute(parsed: any, base: string): string {
const parsedRoute = get('route', parsed)
const route = parsedRoute || `/${this.slug}`
return path.join(base, route)
}
}
4 changes: 1 addition & 3 deletions core/docz/src/components/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import {
HistoryListenerParameter,
} from '@reach/router'

declare var DOCZ_BASE_URL: string

import { doczState } from '../state'
import { useComponents, ComponentsMap } from '../hooks/useComponents'
import { AsyncRoute, loadRoute, Imports } from './AsyncRoute'
Expand Down Expand Up @@ -45,7 +43,7 @@ export const Routes: SFC<RoutesProps> = ({ imports }) => {
<MDXProvider components={components}>
<LocationProvider history={history}>
<React.Suspense fallback={<Loading />}>
<Router basepath={DOCZ_BASE_URL}>
<Router>
<NotFound default />
{entries &&
entries.map(({ key: path, value: entry }) => {
Expand Down

0 comments on commit 9ca39d7

Please sign in to comment.