Javascript 如何通过角js路由
我是angular js的新手,我需要通过以下代码进行路由,但它得到HTTP状态404错误 web控制台显示此消息 localhost:8080/testasd/addStudent加载资源失败:服务器响应状态为404(未找到)Javascript 如何通过角js路由,javascript,angularjs,Javascript,Angularjs,我是angular js的新手,我需要通过以下代码进行路由,但它得到HTTP状态404错误 web控制台显示此消息 localhost:8080/testasd/addStudent加载资源失败:服务器响应状态为404(未找到) 您需要配置web服务器,以便为所有请求的URL发送index.html。这称为重写规则。这是因为web浏览器将对该URL发出GET请求,web服务器希望在该位置找到文件。重写规则允许您拦截该请求并将其重定向到其他文件 web服务器上不存在路由中的URL,但需要加载Ang
您需要配置web服务器,以便为所有请求的URL发送
index.html
。这称为重写规则。这是因为web浏览器将对该URL发出GET
请求,web服务器希望在该位置找到文件。重写规则允许您拦截该请求并将其重定向到其他文件
web服务器上不存在路由中的URL,但需要加载AngularJS。因此,对于所有请求,从web根目录发送index.html
。这假设您正在创建所谓的单页应用程序
对于Apache,在web根目录中创建一个名为.htaccess
的文件
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.html [QSA,L]
</IfModule>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="angular" patternSyntax="Wildcard">
<match url="*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
您希望它转到localhost:8080/testasd/addStudent还是localhost:8080/addStudent?
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="angular" patternSyntax="Wildcard">
<match url="*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>