我已经开始了一个项目,前端有角度J,后端有yii2框架。一切都运行正常,期望网站网址每次包含#/,这是一个令人讨厌的事实。我想隐藏它。我尝试了以下方法:
if(window.history && window.history.pushState){
//$locationProvider.html5Mode(true); will cause an error $location in HTML5 mode requires a tag to be present! Unless you set baseUrl tag after head tag like so: <head> <base href="/">
// to know more about setting base URL visit: https://docs.angularjs.org/error/$location/nobase
// if you don't wish to set base URL then use this
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
}
(头部的基本网址设置...)
我尝试了以下网址:site / test(网站/#/测试正在运行!)
但我从框架中得到错误:
exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request "test".' in C:\xampp\htdocs\angularyii\vendor\yiisoft\yii2\base\Module.php:462
Stack trace:
#0 C:\xampp\htdocs\angularyii\vendor\yiisoft\yii2\web\Application.php(83): yii\base\Module->runAction('test', Array)
#1 C:\xampp\htdocs\angularyii\vendor\yiisoft\yii2\base\Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#2 C:\xampp\htdocs\angularyii\frontend\web\index.php(18): yii\base\Application->run()
#3 {main}
Next exception
'yii\web\NotFoundHttpException' with message 'Page not found.' in C:\xampp\htdocs\angularyii\vendor\yiisoft\yii2\web\Application.php:95
堆栈跟踪:
#0 C:\xampp\htdocs\angularyii\vendor\yiisoft\yii2\base\Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#1 C:\xampp\htdocs\angularyii\frontend\web\index.php(18): yii\base\Application->run()
#2 {main}
我该如何解决这个问题?非常感谢你。