Hi @abhik,
I’m not exactly sure what you’re asking for. Middleman is designed to build a static site. Routing requests dynamically is something that you would handle at the server-level.
It would be odd for Middleman to provide this feature, as users might mistakenly think that setting up this kind of routing in development would somehow magically make it work in production. Middleman doesn’t make any assumptions about what kind of server you’re using.
I don’t know anything about your project, and I also don’t know much about AngularJS, but I would question why you would need to redirect every “non-static” page (I’m not sure what that means in this context). Angular handles the routing for you, doesn’t it? This is a very strange request.
With those caveats, there is in fact a way to get this behaviour in development. You can write custom Rack Middleware to run alongside the development server.
Here’s how I would implement this. Inside a new file, called missing_redirector.rb
:
class MissingRedirector
def initialize(app)
@app = app
end
def call(env)
status, headers, response = @app.call(env)
# Redirect any missing pages to the root route
if status == 404
status = 302
headers['Location'] = '/'
end
[status, headers, response]
end
end
Require the Middleware and ask Middleman to use it in your config.rb
:
require './missing_redirector'
use MissingRedirector
That should do the trick.
Hope that helps!