htmlperlmodel-view-controllercontrollercatalyst

Perl Catalyst - Page not found when using href to link to page on the same site


I am creating a Catalyst application, currently I have a simple login page that also contains a 'Forgotten Password' link. It is all working perfectly, except when I click the 'Forgotten Password' link it should take me to a brand new html page that simply contains the words "Unlucky, you should have remembered it". Instead I get a 'Page not found' error.

What I am doing:

I have a Controller called Login.pm containing the following:

 sub default : Private {
    my ( $self, $c ) = @_;
    $c->forward('login');
 }

 sub login : Path('/login') {   
    my ( $self, $c ) = @_;

    $c->stash->{title} = "Login page";
    $c->stash->{page} = "html";
    $c->stash->{template} = "login.html";
 }

All of the above works correctly and produces the login page.

In the Catalyst root/login.html file (along with all the other bits like buttons) I have the following piece of code that should allow me to link to the 'Forgotten Password' html page.

<p><a href="forgotpassword.html">Forgot Password?</a></p>

The root/forgotpassword.html file it is referencing contains the following:

<!DOCTYPE html>
<html>
<body>

<h1>Unlucky, you should have remembered it</h1>

</body>
</html>

However, when I click the 'Forgotten Password' link on the login page it goes to 'mydomainname/forgotpassword.html' and says 'Page not found'.

Do I need to create a Controller for the forgotpassword page? and if so what would it need to contain? Or is there something obvious I am overlooking?

I am new to Catalyst.


Solution

  • Finally worked out the issue, thanks to 'mikew' for referring me to the 'Serving static content' section of the cookbook on CPAN.

    What the problem was:

    Using the html5 code below I was referencing a simple html page that required no interaction with Catalyst to work.

    <p><a href="forgotpassword.html">Forgot Password?</a></p>
    

    However, as mentioned in the Cookbook and Catalyst::Plugin::Static::Simple

    "By default, the following extensions are not served (that is, they will be processed by Catalyst): tmpl, tt, tt2, html, xhtml."

    and

    "There are some file types you may not wish to serve as static files. Most important in this category are your raw template files. By default, files with the extensions tmpl, tt, tt2, html, and xhtml will be ignored by Static::Simple in the interest of security."

    To prevent the 'Page not found' error (as the html page is ignored by default) you need to do add the following to the MyApp.pm file ensuring that you remove the extension/s you do not want to be ignored (in my case html files).

    MyApp->config(
           static => {
               ignore_extensions => [
                   qw/tmpl tt tt2 xhtml/
               ],
           },
     );