angularjs - Angular Route with multiple slashes override folder path -
i have angular app using ngroute module along html5 mode pushstate cleaner url.
app.config(function($routeprovider, $locationprovider){ $locationprovider.html5mode(true); $routeprovider //route home page .when("/", { templateurl: "templates/main.html", controller: "imagecontroller", }) //route page .when("/me", { templateurl: "templates/me.html", controller: "imagecontroller", }) //404 error .when("/404", { template: "", controller: "imagecontroller", title: "404 error", }) //default route / .otherwise({ redirectto: "/404", }); });
i have changed .htaccess file rewrite trailing slashes ("/").
rewriteengine on rewritebase / # don't rewrite files or directories rewritecond %{request_filename} -f [or] rewritecond %{request_filename} -d rewriterule ^ - [l] # redirect urls without trailing slash rewriterule ^(.*)/$ $1 [l,r=301] # rewrite else index.html allow html5 state links rewriterule ^ index.html [l]
this works great 1 trailing slash, e.g. 'http://example.com/me/' updates 'http://example.com/me' , gets routed accordingly.
however, routing breaks when there multiple slashes, e.g. 'http://example.com/me/foo' routes incomplete page instead of redirecting '/404'. how resolve if '/me/foo' route doesn't exist, gets redirected '/404'.
your issue $route not looking after /me treating 404.
do route if want parameters follow it.
.when("/me/:params?", { // ? allows parameter empty /me , /me/foo both return correct route templateurl: "templates/me.html", controller: "imagecontroller", })
if want retrieve routeparams after route has been called need use $routeparams
in controller or directive so.
scope.myparam = $routeparam.params; //in instince of url above scope.myparams set foo
Comments
Post a Comment