0

Basically title, I would like the router to be able to reroute to a certain page via URL. I would like to be able to move to all my "pages" but I can't find all that much information on how that can be achieved.

https://grimzero.github.io/Portfolio to https://grimzero.github.io/Portfolio/About

To clarify, my router has no issues on my page, I would just like that the page doesnt throw a 404 when it is refreshed somewhere other than the main page.

  • You need to use '#' routing ( search for hash routing ) or configure your htaccess file, I think its not possible in github pages. check the article https://medium.com/wineofbits/angular-2-routing-404-page-not-found-on-refresh-a9a0f5786268 – Akhil Aravind Mar 10 '20 at 10:29
  • I will try this out, I saw that post but assumed (probably wrongfully) that it wouldn't be relevant for angular 9 as it is angular 2. – Torben Van Assche Mar 10 '20 at 10:32
  • its 100% right answer. since its not angular js, it should work in angular 2+ – Akhil Aravind Mar 10 '20 at 10:33
  • That worked. I do wonder why this is not the default implementation. Do you know why we need to specify it like this to work like that? – Torben Van Assche Mar 10 '20 at 10:42
  • angular, react etc are SPA, it has only one entry point. from there it works on Routing. All SPA has only a index file, and components are loaded on the basis of routing path. So when we load `www.page.com` it loads the index file, when we load `www.page.com/about` it loads the about file ( remember file ). In SPA, there is no such file, we are only loading components. so when we try to load `url /about`, it looks for `about` file which in out case is not there. So a 404 error is thrown – Akhil Aravind Mar 10 '20 at 11:15
  • That actually makes sense, but why is the way with the # not standard? It seems like refreshing a page and getting a 404 is just an oversight isnt it? – Torben Van Assche Mar 10 '20 at 12:08
  • 1
    we can use hash not only in SPA, but in other also. You should have seen some thing like when we click on 'about' in the nav, page will scroll down to the about section, that is done with `#`, similarly in here ( I think so, may be it has some other explanation ), when we use hash routing, it will always point to index page and the index page will then look after the routing. – Akhil Aravind Mar 10 '20 at 12:16
  • like `example.com/#/about` when it is loaded, it will fall back to index page and from there routing algorithm will see a `#/about` there, then it will load the about component. But if we remove the `#`, eg. `example.com/about`, now its looking for folder or file named about in the example context. Does that makes sense bro :). ( sorry I am very bad in explaining something I know how it works ) – Akhil Aravind Mar 10 '20 at 12:18
  • I see what you mean, that makes sense. You aren't that bad at explaining lol – Torben Van Assche Mar 10 '20 at 12:31

0 Answers0