Home > Blockchain >  Change location of controller pages
Change location of controller pages

Time:10-08

I have a simple IHP application which converts farenheit to celsius.

I've stripped out many of the files so that the bulk of the app is in the following file:

enter image description here

After submitting that form, the following page is shown:

enter image description here

Question

As you can see, the two pages are at /Form and /Result.

What's a good way to have these show up at:

/Temperature/Form
/Temperature/Result

instead?

Update

Here's a new version of the code based on Marc's answer below:

https://github.com/dharmatech/ConvertTemperatureIhp/blob/002-routing/Web/FrontController.hs

CodePudding user response:

Check out the guide on Custom Routing https://ihp.digitallyinduced.com/Guide/routing.html#custom-routing

Basically you need to remove the instance AutoRoute TemperatureController and replace it with this:

instance CanRoute TemperatureController where
    parseRoute' = do
        let form = string "/Temperature/Form" <* endOfInput >> pure FormAction
        let result = string "/Temperature/Result" <* endOfInput >> pure ResultAction
        form <|> result

instance HasPath TemperatureController where
    pathTo FormAction = "/Temperature/Form"
    pathTo ResultAction = "/Temperature/Result"
  • Related