Angular JS with Yii 2, hide # from url

Saturday, October 3, 2015

I have started a project, with angular Js on frontend, and yii2 framework as back end. Everything is working fine, expect the fact that the Site url contains a #/ every time, and it is annoing. I would like to hide it. I tried the following :

        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
        });
    }

But I am getting an error from the framework :

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
Stack trace:

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}

How can i solve this problem ? Thank you very much.


0 comments:

Post a Comment