在基于本地文件的应用程序(带文件://)时,是否可以使用AngularJS进行HTML5模式URL路由

时间:2022-03-25 10:46:05

I appligize if this has already been asked already but I can not find any information about this.

我知道如果已经提出这个问题但我找不到任何相关信息。

I have an AngularJS application which will be accessed from the hard drive (not from a HTTP server) so the URL in the address will be something like file:///home/user/desktop/app.html)

我有一个AngularJS应用程序,它将从硬盘驱动器(而不是从HTTP服务器)访问,因此地址中的URL将类似于file:///home/user/desktop/app.html)

I am not able to get HTML5-mode URL routing to work. I am using UI-routing module for AngularJS, and whenever I go to file://..../app.html/somepage), the routing does not work. If I set HTML5 mode to false in $locationProvider, and then I go to file://.../app.html#/somepage then it does work.

我无法使HTML5模式URL路由工作。我正在为AngularJS使用UI路由模块,每当我去file://.... / app.html / somepage)时,路由都不起作用。如果我在$ locationProvider中将HTML5模式设置为false,然后我转到file://.../app.html#/somepage然后它确实有效。

So is it possible to do? Can someone show me a example where file://-hosted app can with with a URL like file:///myapp.html/somepage ??

那有可能吗?有人可以给我看一个例子:file://托管的应用程序可以使用像file:///myapp.html/somepage这样的URL吗?

Thanks

1 个解决方案

#1


2  

No. The file:// pseudo-protocol directly queries the local filesystem. For 'fancy' URLs like /myapp.html/somepage to work you need to have a mechanism in between, like Apache's mod_rewrite or FallbackResource which handles those fancy URLs. Since those don't work on the file system, you're out of luck.

不可以.file://伪协议直接查询本地文件系统。对于像/myapp.html/somepage这样的“花哨”网址,你需要在它们之间建立一种机制,比如Apache的mod_rewrite或FallbackResource来处理那些花哨的URL。由于那些不适用于文件系统,你运气不好。

Install something like XAMPP to test websites locally through a webserver that is capable of these things.

安装像XAMPP这样的东西,通过能够做这些事情的网络服务器在本地测试网站。

#1


2  

No. The file:// pseudo-protocol directly queries the local filesystem. For 'fancy' URLs like /myapp.html/somepage to work you need to have a mechanism in between, like Apache's mod_rewrite or FallbackResource which handles those fancy URLs. Since those don't work on the file system, you're out of luck.

不可以.file://伪协议直接查询本地文件系统。对于像/myapp.html/somepage这样的“花哨”网址,你需要在它们之间建立一种机制,比如Apache的mod_rewrite或FallbackResource来处理那些花哨的URL。由于那些不适用于文件系统,你运气不好。

Install something like XAMPP to test websites locally through a webserver that is capable of these things.

安装像XAMPP这样的东西,通过能够做这些事情的网络服务器在本地测试网站。