onury/docma

routing path refresh leads to 404

aaronmallen opened this issue · 12 comments

Using app.routing path will result in 404 on page refresh. links in the nav menu will take you to the expected page but on page refresh a trailing / is added to the url and a 404 Page not found is displayed.

{
  "src": [
    {
      "interface": [
        "./src/**/*.js",
        "!./src/internal/**"
      ],
      "internal": [
        "./src/internal/**/*.js"
      ],
    },
    "./LICENSE:md",
    "./CHANGELOG.md",
    "./CODE_OF_CONDUCT.md",
    "./CONTRIBUTING.md",
    "./docs/**/*.md"
  ],
  "dest": "./docs/.out",
  "app": {
    "title": "MyLib",
    "entrance": "content:readme",
    "server": "github",
    "routing": "path"
  },
  "template": {
    "navbar": {
      "menu": [
        {
          "label": "Docs",
          "iconClass": "fas fa-book",
          "items": [
            {
              "label": "Getting Started",
              "href": "/content/getting_started"
            },
            {
              "label": " API",
              "href": "/api/interface",
              "iconClass": "fas fa-code fa-sm"
            },
            {
              "label": "Lib",
              "href": "/api/internal",
              "iconClass": "fab fa-dev fa-sm"
            }
          ]
        }
      ]
    }
  }
}
$ node -v
v10.13.0
$ npm -v
6.4.1
$ node_modules/.bin/docma -v

3.0.0
onury commented

You have "entrance": "content:readme" but you don't have any route named readme in your src.

AND Pls read the docs thoroughly before opening multiple issues you're not sure of. I'm providing these open source projects for free but I don't have that much free time. So please read the docs...

@onury readme.md is in docs/ please reopen

Also Readme loads fine the issue is with the two api paths

onury commented

Try updating your hrefs without a leading slash (/) which results in an absolute path rather than relative. e.g. "api/interface" instead of "/api/interface".

Lastly I appreciate you and this project and have read the docs extensively both from your site AND from the source itself ;)

Still reproducible when using relative paths in the config. To be clear its not a generic 404 thats being loaded its a docma generated page for 404 with the nav and everything still present. You can even just click the link from the nav to make it redirect to the right page.

To reproduce:

  1. set app.routing to path in your config
  2. have 2 "named" api's (i.e. 'api1', 'api2') in the src of your config
  3. docma serve and goto localhost:9000
  4. attempt to goto localhost:9000/api/api1 or use a link in the navigation to go to 'api1'

When using a link from the navigation the page will load, but upon refresh a trailing / will be appended to the url and a 404 is returned, when attempting to go directly to the page via url a trailing / will be appended to the url and a 404 returned.

So for example: http://localhost:9000/api/api1#MyModule.myFunctionwill be http://localhost:9000/api/api1/#MyModule.myFunction after or refresh or when trying to access the url directly.

Uncaught Error: Page or content not found for route: {}
    at docma-web.js:38
    at Stub.callback (docma-web.js:38)
    at Stub.flush (docma-web.js:4)
    at Chunk.setError (docma-web.js:4)
    at Object.dust.render (docma-web.js:4)
    at DocmaWeb._render (docma-web.js:38)
    at DocmaWeb._render404 (docma-web.js:38)
    at DocmaWeb.render (docma-web.js:38)
    at DocmaWeb.Route.apply (docma-web.js:40)
    at docma-web.js:49
onury commented

This is a bug in the core dependency page.js.
I've opened an issue there and also sent a PR to fix it.

If they don't merge this soon, I'll use my fixed version of page.js in the new Docma release (that has some other fixes).

Thanks for reporting.

onury commented

Fixed in Docma 3.1.0.
Let me know if it works for you.

Works great! Thank you @onury

I have this docma json file test:

{ "src": [ "./src/components/**/*.js", "./README.md" ], "dest": "./src/docs" }

When I execute, yarn docma -c docma.json it works but when I visit the generated index.html I'm getting the following:
screen shot 2019-01-22 at 10 54 49 am

The same error: Uncaught Error: Page or content not found for route: {}

I have "docma": "^3.2.2", in my package json. I'm not sure if I need to configure something else, it's just a simple test.

Best regards.

onury commented

You cannot view the generated app by opening (double-clicking) the index.html. You need to serve the app locally to test it. You can use docma serve command.

And according to your docma.json config, you should have these routes:

  • <your-docs-root>/?api : generated from your .js files
  • <your-docs-root>/?content=readme : generated from README.md

Please read the documentation and F.A.Q. section is also helpful.