Route to Angular home page

Asked

Viewed 929 times

0

I have the following structure in my module

https://jsfiddle.net/o0hs0uhw/

When I call the URL http://localhost/emp/dist/boffice/home, it includes the home.html view, so far so ok. The problem is that when it is in this URL and I give a enter, it gives me a message that the page was not found. Same thing if I type the URL and put the /home at the end, it presents me the same error. Does anyone know how to fix it? Thank you

1 answer

1


The problem is that you enabled html5, so that the route system works properly using $locationProvider.html5Mode(true); you should also set the root of your app. This is done inside your head through the tag

    <base href="/">
</head>

Or, if your app has a different root folder, set it there, for example:

<base href="/app/">
//ou
<base href="/app/adm/">

Another point to note (that I have already been through this problem) is that with this method may be that your links break, one of the solutions would be to use a / before the definition of your links, such as css, script, etc.. For example, the following css:

<link rel="stylesheet" href="dist/css/main.min.css">

Would look like this:

<link rel="stylesheet" href="/dist/css/main.min.css"> //Note a barra invertida antes do dist

Also remembering that for different servers, there are different solutions, as for example, in apache I needed to enable the module rewrite, and so on. Test with these solutions I gave you, if you still don’t solve, your problem may be related to the server you are using.

  • Thanks friend, tomorrow I will test

  • So, it worked. But now there’s one though, I’ve changed the structure and now the homepage is only in / (before it was /home). Now for example if I put /test, presents me the error page. From what I saw on the console, is not loading the "test.html", it shows only "test". This if I enable Html5. With it disabled is normal

  • This should be associated with the way you mount your routes. I, for example, use ui-router and have set a default redirect. When the user accesses site or site/ (for example) it automatically directs to site/home. Apart from that, it is also necessary to define a url for each stete. This using ui-router, which may be different for you if you use another route system.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.