我使用docsify有好几个月了,最近买了域名,然后也成功实现了把个人域名加进去。可是现在每次链接都是mydomain.com/#/document_01 mydomain.com/#/zh_cn/document_01 总是有/#/ 我怎样才能去掉每篇文章链接中的/#/
https://docsify.js.org/#/configuration?id=routermode
On Wed, Dec 19, 2018, 10:54 PM LiHuashen <[email protected] wrote:
我使用docsify有好几个月了,最近买了域名,然后也成功实现了把个人域名加进去。可是现在每次链接都是
mydomain.com/#/document_01 mydomain.com/#/zh_cn/document_01 总是有/#/
我怎样才能去掉每篇文章链接中的/#/—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/docsifyjs/docsify/issues/720, or mute the thread
https://github.com/notifications/unsubscribe-auth/AXmHhPC8ul4dWzcXOOZYUIiWakMD78_gks5u6lMsgaJpZM4ZaZm2
.
谢谢!我昨晚试了把rountermode配置成history模式,可以去掉#,可是每次刷新页面,就出现404了,我查到vuejs,是这样规定的,不过可以有解决方案。你有解决方案吗?我不是很懂前端
刷新的话确实是不能访问的:

看了一下 vuejs 对 History Mode 的解释,这是因为使用了 pushState,这样我们才能够到达指定 URL 而不用重新加载页面。而刷新的时候是直接请求的,如果服务端不加配置的话就会直接返回 404。
vuejs 的文档中已经给出了解决方案,就是在刷新请求其他页面的时候,都将其重定向到 index.html 就行。
比如我用的 Nginx,配置如下:
location / {
try_files $uri $uri/ /index.html;
}
效果如下:
https://katex.upupming.site/supported
另外:Github Pages 是静态资源托管,应该是不支持这种处理的,所以必须使用带服务端技术的托管服务,Firebase、now.sh、heroku 这几个应该都是可以的。
非常感谢!我试下部署到netlify上看能不能试下这种操作
For the English speakers/readers:
using the history routerMode will error with a return of
Cannot GET /some-route
as the web page doesn't hit the index.html that has Docsify in it, so it can't then route to the correct .md resource and process it for rendering.
To fix this, you must configure your hosting server to redirect any non-root URLs to the root. That is: yoursite.com/apples should redirect to yoursite.com/, Docsify will load and then should send you to the /apples route.
With Firebase Hosting & Docsify "routerMode": "history" your Hosting rules should be:
{
"hosting": {
"public": "docs",
"ignore": [".*"],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
This will re-route every URL under your domain and send it to /index.html
Issues: the sidebar header defaults to window.location.pathname which is not / when you load a non-root route. That is, yoursite.com/apples is the current pathname despite the Firebase Hosting rewrite. To fix this, you should use the Docisify config nameLink.
My config with the above Firebase Hosting config is:
// history mode routing
routerMode: "history",
nameLink: "/",
Thanks to everyone here for investigating and Google Translate :100:
I will endeavour to update the docs with this information.
@jthegedus great job! Closing this issue. I've created #759 to improve docs.
For the English speakers/readers:
using the
historyrouterMode will error with a return ofCannot GET /some-route
as the web page doesn't hit the
index.htmlthat has Docsify in it, so it can't then route to the correct.mdresource and process it for rendering.To fix this, you must configure your hosting server to redirect any non-root URLs to the root. That is:
yoursite.com/applesshould redirect toyoursite.com/, Docsify will load and then should send you to the/applesroute.With Firebase Hosting & Docsify
"routerMode": "history"your Hosting rules should be:{ "hosting": { "public": "docs", "ignore": [".*"], "rewrites": [ { "source": "**", "destination": "/index.html" } ] } }This will re-route every URL under your domain and send it to
/index.htmlIssues: the sidebar header defaults to
window.location.pathnamewhich is not/when you load a non-root route. That is,yoursite.com/applesis the current pathname despite the Firebase Hosting rewrite. To fix this, you should use the Docisify confignameLink.My config with the above Firebase Hosting config is:
// history mode routing routerMode: "history", nameLink: "/",Thanks to everyone here for investigating and Google Translate 💯
I will endeavour to update the docs with this information.
The docs which how to deploy documents to NOW.sh does not detailed enough. Please update it. Thanks so much!!
Here's the docs I talk about just now.
https://docsify.js.org/#/ssr
@watson8544
You can refer the now.sh docs at https://zeit.co/docs/v1/, and this repo https://github.com/zeit/now-examples may help.
By the way, you should be clear about the difference between v1 and v2 of now.sh.
There is a lot of work to improve the hosting docs. I will endeavor to improve them when I get a change. The changes I think need to be made are:
routerMode do the various hosting services support/preferhttps://docsify.js.org/#/helpers?id=ignore-to-compile-link
@jthegedus How to use "routerMode": "history" for Github Pages? I cannot redirect any non-root URLs to the root.
Related Issue: https://github.com/docsifyjs/docsify/issues/238
Most helpful comment
There is a lot of work to improve the hosting docs. I will endeavor to improve them when I get a change. The changes I think need to be made are:
routerModedo the various hosting services support/prefer